Re: substitute variable in sql?
От | am@fx.ro |
---|---|
Тема | Re: substitute variable in sql? |
Дата | |
Msg-id | 20021030003109.B273@coto обсуждение исходный текст |
Ответ на | Re: substitute variable in sql? (Bruno Wolff III <bruno@wolff.to>) |
Список | pgsql-general |
> On Tue, Oct 29, 2002 at 11:35:42 -0500, > "Johnson, Shaunn" <SJohnson6@bcbsm.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@fx.ro)
В списке pgsql-general по дате отправления: