Re: problem with selects based on dates

From: Szabo Zoltan <col(at)econet(dot)hu>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: problem with selects based on dates
Date: 2001-09-07 10:22:45
Message-ID: 3B989FF4.59BB03F1@econet.hu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

"J.H.M. Dassen (Ray)" wrote:

> Mike Withers <M(dot)withers(at)uws(dot)edu(dot)au> wrote:
> > db2001=# SELECT * FROM emp WHERE hiredate > 1981-01-01;
> ^^^^^^^^^^
>
> > It is not clear to me why in the last query the 1980-12-17 hiredate record
> > is selected as well.
>
> There are no quotes around what you intend to be the date. Thus it is
> evaluated as an expression, resulting in 1979. Try
> SELECT * FROM emp WHERE hiredate > '1981-01-01';

But better to use: to_date( '1981-01-01','YYYY-MM-DD')
SELECT * FROM emp WHERE hiredate > to_date( '1981-01-01','YYYY-MM-DD')

CoL

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Corn 2001-09-07 12:25:07 is it support table partitioning?
Previous Message cnliou 2001-09-07 08:24:09 What Is The Firing Order?