pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeff Boes <jeff@endpoint.com>
To: pgsql-sql@postgresql.org
Subject: Re: psql client: technique for applying default values to :variables?
Date: Sat, 14 Jan 2006 09:54:46 -0500
Message-ID: <43C910B6.9080904@endpoint.com> (raw)
In-Reply-To: <6d8daee30601111551y68b2663ek6484c830f2107bee@mail.gmail.com>
References: <43C55316.60403@endpoint.com>
	<6d8daee30601111551y68b2663ek6484c830f2107bee@mail.gmail.com>

<!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@mail.gmail.com"
 type="cite">
  <pre wrap="">On 1/11/06, Jeff Boes <a class="moz-txt-link-rfc2396E" href="mailto:jeff@endpoint.com">&lt;jeff@endpoint.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@endpoint.com">jeff@endpoint.com</a>
</pre>
</body>
</html>



view thread (6+ messages)  latest in thread

Message-ID: <43C910B6.9080904@endpoint.com>
Permalink:  ../43C910B6.9080904@endpoint.com/
Also on:    postgresql.org/message-id/43C910B6.9080904@endpoint.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jeff@endpoint.com
  Subject: Re: psql client: technique for applying default values to :variables?
  In-Reply-To: <43C910B6.9080904@endpoint.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox