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

From: Jeff Boes <jeff(at)endpoint(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: psql client: technique for applying default values to :variables?
Date: 2006-01-14 14:54:46
Message-ID: 43C910B6.9080904@endpoint.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Tony Wasson wrote:
<blockquote
cite="mid6d8daee30601111551y68b2663ek6484c830f2107bee(at)mail(dot)gmail(dot)com"
type="cite">
<pre wrap="">On 1/11/06, Jeff Boes <a class="moz-txt-link-rfc2396E" href="mailto:jeff(at)endpoint(dot)com">&lt;jeff(at)endpoint(dot)com&gt;</a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Stumped: is there 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 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.<br>
<br>
<tt>$ psql -v edate=2004-01-01<br>
...<br>
=&gt; \set edate 'CURRENT_DATE::DATE'<br>
=&gt; select :edate;<br>
&nbsp;&nbsp;&nbsp; date<br>
------------<br>
&nbsp;2006-01-14<br>
<br>
<br>
</tt><br>
<pre class="moz-signature" cols="72">--
Jeffery Boes &lt;&gt;&lt;
<a class="moz-txt-link-abbreviated" href="mailto:jeff(at)endpoint(dot)com">jeff(at)endpoint(dot)com</a>
</pre>
</body>
</html>

Attachment Content-Type Size
unknown_filename text/html 1.6 KB

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Glaesemann 2006-01-14 22:38:39 Re: psql client: technique for applying default values to :variables?
Previous Message Alan Chandler 2006-01-14 14:28:00 Re: Another orderby problem