passing values into .sql scripts

From: Geoffrey Knauth <geoff(at)knauth(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: passing values into .sql scripts
Date: 2005-09-15 21:27:52
Message-ID: 8471ACDB-449A-4E67-8804-4407E81420B9@knauth.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I want to do something like this:

\set tmp :acct 'a value'
\i query.sql

where query.sql looks like this:

select sum(amount), dr_acct from ledger where dr_acct = :acct
group by dr_acct;
select sum(amount), cr_acct from ledger where cr_acct = :acct
group by cr_acct;
select
(select sum(amount) from ledger where dr_acct = :acct )
- (select sum(amount) from ledger where cr_acct = :acct );

However, this is what I get:

psql:pnc.sql:1: ERROR: column "a value" does not exist

Is there a different way I should be doing this? (I'm used to
Oracle's &1...&n parameters.)

Geoffrey
--
Geoffrey S. Knauth | http://knauth.org/gsk

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message The One 2005-09-15 21:36:25 How to install Postgresql 8 on different drive letter?
Previous Message Tom Lane 2005-09-15 13:56:01 Re: Triggers & Conditional Assignment