Re: psql client: technique for applying default values to :variables?
От | Jeff Boes |
---|---|
Тема | Re: psql client: technique for applying default values to :variables? |
Дата | |
Msg-id | 43C910B6.9080904@endpoint.com обсуждение исходный текст |
Ответ на | Re: psql client: technique for applying default values to :variables? (Tony Wasson <ajwasson@gmail.com>) |
Ответы |
Re: psql client: technique for applying default values to :variables?
|
Список | 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 по дате отправления: