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

From: Andreas Seltenreich <andreas+pg(at)gate450(dot)dyndns(dot)org>
To: Jeff Boes <jeff(at)endpoint(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: psql client: technique for applying default values to :variables?
Date: 2006-01-16 17:02:25
Message-ID: 87psmsumvy.fsf@gate450.dyndns.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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
--

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Alvaro Herrera 2006-01-16 17:05:15 Re: For update
Previous Message Ottó Havasvölgyi 2006-01-16 16:59:33 For update