Re: psql client: technique for applying default values to :variables? - Mailing list pgsql-sql

From Jeff Boes
Subject Re: psql client: technique for applying default values to :variables?
Date
Msg-id 43CBBCD3.80506@endpoint.com
Whole thread Raw
In response to Re: psql client: technique for applying default values to :variables?  (Michael Glaesemann <grzm@myrealbox.com>)
Responses Re: psql client: technique for applying default values to :variables?  (Andreas Seltenreich <andreas+pg@gate450.dyndns.org>)
List pgsql-sql
Michael Glaesemann wrote:
>
> On Jan 14, 2006, at 23:54 , Jeff Boes wrote:
>
>> Tony Wasson wrote:
>
>>
>> Sure, but that was not my question. I want to be able to set the
>> variable on the command line, BUT have it default to a value inside
>> the SQL script if not present on the command line.
>
> 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...


-- 
Jeffery Boes  <><
jeff@endpoint.com



pgsql-sql by date:

Previous
From: John DeSoi
Date:
Subject: Re: Executing plpgsql scripts using psql, is that possible?
Next
From: Ottó Havasvölgyi
Date:
Subject: For update