Re: How to pass parameters into a sql script ?

From: "Atul Chojar" <achojar(at)airfacts(dot)com>
To: "'Vyacheslav Kalinin'" <vka(at)mgcp(dot)com>
Cc: <pgsql-admin(at)postgresql(dot)org>, "'Andy Yoder'" <ayoder(at)airfacts(dot)com>
Subject: Re: How to pass parameters into a sql script ?
Date: 2009-05-28 18:06:27
Message-ID: 008f01c9dfbf$05b1dd60$11159820$@com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Thanks - with quoting, the 2nd select (select count(*) from
prod_debit_payments_unapplied where when_received = :p_date;) works.

Thanks!

atul

<http://www.airfacts.com/> AirFacts, Inc.
8120 Woodmont Ave., Suite 700
Bethesda, MD 20814
Tel: 301-760-7315

From: Vyacheslav Kalinin [mailto:vka(at)mgcp(dot)com]
Sent: Thursday, May 28, 2009 12:10 PM
To: Atul Chojar
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: [ADMIN] How to pass parameters into a sql script ?

Looks like quoting issue.
Try this one:

$ psql -d us_audit -e -1 -v p_date=\'20081023\' -f chk_param.sql
select count(*) from prod_debit_payments_unapplied where when_received =
(select :p_date::char(8));

or even

select count(*) from prod_debit_payments_unapplied where when_received =
:p_date;

On Thu, May 28, 2009 at 6:57 PM, Atul Chojar <achojar(at)airfacts(dot)com> wrote:

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';

...

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.339 / Virus Database: 270.12.40/2135 - Release Date: 05/28/09
08:10:00

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Anj Adu 2009-05-28 23:22:15 Pre-creating partitions incurs insert penalty
Previous Message Ibrahim Shaame 2009-05-28 17:28:55 Cannot compile pgadmin3-1.10.0-beta3