Re: How to convert postgres timestamp to date: yyyy-mm-dd

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Vivek Khera <vivek(at)khera(dot)org>
Cc: Postgres General List <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to convert postgres timestamp to date: yyyy-mm-dd
Date: 2008-03-11 20:50:50
Message-ID: 5632.1205268650@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Vivek Khera <vivek(at)khera(dot)org> writes:
> On Mar 11, 2008, at 2:50 PM, A. Kretschmer wrote:
>>>> i.e ... WHERE pt.created_date >= '2008-01-21'
>>
>> You can't compare a date or timestamp to a varchar or text. For your
>> example, cast the date-string to a real date like:

> Since which version of Pg?
> Queries like the above have worked for me from 7.3 up thru 8.1, which
> is my current production environment.

The above example is not in fact comparing to a varchar or text value.
It's comparing to an unknown-type literal constant, which will
preferentially be resolved as being the same type as the variable
it's being compared to.

Whether you can do a cross-data-type comparison between two variables of
known data types is a whole 'nother story. PG 8.3 insists on an
explicit cast in some cases where earlier versions silently did a
(possibly surprising) type conversion.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrej Ricnik-Bay 2008-03-11 20:51:43 Re: Trigger to run @ connection time?
Previous Message sam 2008-03-11 20:49:50 Trouble with Savepoints in postgres