From: | am(at)fx(dot)ro |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: substitute variable in sql? |
Date: | 2002-10-29 22:31:09 |
Message-ID: | 20021030003109.B273@coto |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
> On Tue, Oct 29, 2002 at 11:35:42 -0500,
> "Johnson, Shaunn" <SJohnson6(at)bcbsm(dot)com> wrote:
> > --thanks for the reply
> >
> > --i just have an sql script that i launch
> > --by hand (psql -U <user> -d <database> -f ./<script>)
> >
> > --the date is a rolling date which is supposed to
> > --change every 3 months. and as variable 1 is moved
> > --up every month, so should variable 2 move up every
> > --month.
You could create a template script which contains
DATA_1 for the first parameter and DATA_2 for the second
parameter.
Then, use sed to replace DATA_1 and DATA_2
with the actual values.
--- edit a.sql :
select * from tbl where ddata between DATA_1 and DATA_2;
--- run sed :
sed -e 's/DATA_1/10-09-2002/' -e 's/DATA_2/10-12-2002/' a.sql > b.sql
--- cat b.sql :
select * from tbl where ddata between 10-09-2002 and 10-12-2002;
--- run the script :
psql -f b.sql
( I think this solution could be improved by using pipes ,
in order to avoid the temporary b.sql file ... )
Adrian Maier
(am(at)fx(dot)ro)
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2002-10-29 22:41:36 | Re: Formatting query output |
Previous Message | Tom Lane | 2002-10-29 22:31:02 | Re: User functions not displayed by \df |