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

From: Tony Wasson <ajwasson(at)gmail(dot)com>
To: Jeff Boes <jeff(at)endpoint(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: psql client: technique for applying default values to :variables?
Date: 2006-01-11 23:51:00
Message-ID: 6d8daee30601111551y68b2663ek6484c830f2107bee@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 1/11/06, Jeff Boes <jeff(at)endpoint(dot)com> wrote:
> 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')

Stuff like this works for me in a SQL file....

\set edate 'CURRENT_DATE::DATE'

SELECT * FROM some_table WHERE update_date = :edate;

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2006-01-12 03:02:21 Re: foreign keys with on delete cascade and triggers
Previous Message Dirk Jagdmann 2006-01-11 22:56:40 foreign keys with on delete cascade and triggers