How to pass parameters into a sql script ? - Mailing list pgsql-general

From Atul Chojar
Subject How to pass parameters into a sql script ?
Date
Msg-id 003a01c9dfa3$9f750740$de5f15c0$@com
Whole thread Raw
In response to Re: thanks for the "testing" replies ; now my first question - Logs say update done but not actually done or committed into database  (Filip Rembiałkowski <plk.zuber@gmail.com>)
Responses Re: How to pass parameters into a sql script ?  (Osvaldo Kussama <osvaldo.kussama@gmail.com>)
List pgsql-general

We are unable to pass parameters into any sql script. Could anyone look at the test below and give any suggestions? PostgreSQL version is 8.2.7, running on Linux.

 

Test Script

========

$ cat chk_param.sql

select ''''||:p_date::char(8)||'''';

select count(*) from prod_debit_payments_unapplied where when_received = (select ''''||:p_date::char(8)||'''');

select count(*) from prod_debit_payments_unapplied where when_received = '20081023';

 

Test Results

=========

$ psql -d us_audit -e -1 -v p_date='20081023' -f chk_param.sql

Timing is on.

select ''''||20081023::char(8)||'''';

  ?column? 

------------

 '20081023'

(1 row)

 

Time: 1.474 ms

select count(*) from prod_debit_payments_unapplied where when_received = (select ''''||20081023::char(8)||'''');--same results with direct assignment and to_date

 count

-------

     0

(1 row)

 

Time: 36.290 ms

select count(*) from prod_debit_payments_unapplied where when_received = '20081023';

 count

-------

   193

(1 row)

 

Time: 17.722 ms

 

Thanks!

atul

AirFacts, Inc.
8120 Woodmont Ave., Suite 700
Bethesda, MD 20814
Tel: 301-760-7315

Attachment

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Multidimensional array definition in composite type appears parsed as string
Next
From: inf200468@ucf.edu.cu
Date:
Subject: modo texto