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

From: Jeff Boes <jeff(at)endpoint(dot)com>
To:
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: psql client: technique for applying default values to :variables?
Date: 2006-01-16 15:33:39
Message-ID: 43CBBCD3.80506@endpoint.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)endpoint(dot)com

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Ottó Havasvölgyi 2006-01-16 16:59:33 For update
Previous Message John DeSoi 2006-01-16 13:50:58 Re: Executing plpgsql scripts using psql, is that possible?