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 43C910B6.9080904@endpoint.com
Whole thread Raw
In response to Re: psql client: technique for applying default values to :variables?  (Tony Wasson <ajwasson@gmail.com>)
Responses Re: psql client: technique for applying default values to :variables?  (Michael Glaesemann <grzm@myrealbox.com>)
List pgsql-sql
Tony Wasson wrote: <blockquote cite="mid6d8daee30601111551y68b2663ek6484c830f2107bee@mail.gmail.com" type="cite"><pre
wrap="">On1/11/06, Jeff Boes <a class="moz-txt-link-rfc2396E"
href="mailto:jeff@endpoint.com"><jeff@endpoint.com></a>wrote: </pre><blockquote type="cite"><pre wrap="">Stumped:
isthere any way to set up default values for psql variables
 
within the .SQL file itself? Obviously, I can do something like:

$ psql -f my_script -v MYVAR=${myvar:-mydefault}

but I would prefer to have the value stored with the .SQL file, e.g. (if
this actually worked):

\set MYVAR COALESCE(:MYVAR,'mydefault')   </pre></blockquote><pre wrap="">
Stuff like this works for me in a SQL file....

\set edate 'CURRENT_DATE::DATE'

SELECT * FROM some_table WHERE update_date = :edate; </pre></blockquote><br /> Sure, but that was not my question. I
wantto be able to set the variable on the command line, BUT have it default to a value inside the SQL script if not
presenton the command line.<br /><br /><tt>$ psql -v edate=2004-01-01<br /> ...<br /> => \set edate
'CURRENT_DATE::DATE'<br/> => select :edate;<br />     date<br /> ------------<br />  2006-01-14<br /><br /><br
/></tt><br/><pre class="moz-signature" cols="72">-- 
 
Jeffery Boes  <><
<a class="moz-txt-link-abbreviated" href="mailto:jeff@endpoint.com">jeff@endpoint.com</a>
</pre>

pgsql-sql by date:

Previous
From: Alan Chandler
Date:
Subject: Re: Another orderby problem
Next
From: Michael Glaesemann
Date:
Subject: Re: psql client: technique for applying default values to :variables?