Re: Date variables in psql

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Francisco Reyes <lists(at)natserv(dot)com>
Cc: pgsql General List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Date variables in psql
Date: 2004-10-07 17:25:50
Message-ID: 181.1097169950@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Francisco Reyes <lists(at)natserv(dot)com> writes:
> Trying the following simple sql file:
> \set proc_date 6/30/2004
> \echo Date is :proc_date
> select * from feeds where date = :proc_date limit 20;

That's going to expand to

select * from feeds where date = 6/30/2004 limit 20;

whereas what you need is

select * from feeds where date = '6/30/2004' limit 20;

It's fairly painful to get single quotes into a psql variable;
AFAIK you have to do it like this:

\set proc_date '\'6/30/2004\''

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Frankel 2004-10-07 17:29:45 Re: interfaces for python -- thanks
Previous Message Francisco Reyes 2004-10-07 17:14:58 Date variables in psql