Re: psql client: technique for applying default values to :variables?

Поиск
Список
Период
Сортировка
От Andreas Seltenreich
Тема Re: psql client: technique for applying default values to :variables?
Дата
Msg-id 87psmsumvy.fsf@gate450.dyndns.org
обсуждение исходный текст
Ответ на Re: psql client: technique for applying default values to :variables?  (Jeff Boes <jeff@endpoint.com>)
Список pgsql-sql
Jeff Boes writes:

> Michael Glaesemann wrote:
>> You could write a wrapper script that would accept a command line
>> argument and load the file with the appropriate SET statement prepended.
>
> Which really gains me nothing over just:
>
> $ psql -f myscript.sql -v "MYVAR=${myvar:-default}"
>
> The original question was: how can I store the default value in the
> "myscript.sql" script where it's used, rather than have it in a calling
> script? The aim here was to put the default in the code, so they would
> be bound together...

How about using the traditional Unix macro processor "m4" instead of
psql's variables?

E.g., you could write a myscript.sql.m4 file with m4 variables instead
of psql ones. You could then use ifdef() to test for previous
definitions, or even define a default()-wrapper macro.

regards,
Andreas
-- 


В списке pgsql-sql по дате отправления:

Предыдущее
От: Ottó Havasvölgyi
Дата:
Сообщение: For update
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: For update