Skip site navigation (1) Skip section navigation (2)

Re: Using SELECT WHERE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michal Lijowski <michal(at)cvu(dot)wustl(dot)edu>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Using SELECT WHERE
Date: 2004-04-20 18:00:57
Message-ID: 20848.1082484057@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-novice
Michal Lijowski <michal(at)cvu(dot)wustl(dot)edu> writes:
> I made a database and I would like to select entries 
> which have data not equal to the specified date.

> RabStudies=> SELECT RabNo, ImplantDate, Comments    FROM RabStudiesInfo
> where  implantdate <> 0001-01-01;

What you have on the right there is an integer expression with a value
of -1 (one minus one minus one).  You need to put quotes around it to
make it be treated as a date constant:

	where  implantdate <> '0001-01-01';

Just FYI, pretty much any non-numeric literal has to be quoted as if it
were a string.  Postgres usually infers the specific type from context
--- here, since you're comparing to a column of type date, the
unspecified-type literal will be presumed to be a date.  You can add an
explicit cast if you need to force the literal to be converted to a
specific datatype.

	where  implantdate <> cast('0001-01-01' as date);
	where  implantdate <> '0001-01-01'::date;

The CAST syntax is SQL-standard, the :: syntax is a Postgres-ism.

			regards, tom lane

In response to

pgsql-novice by date

Next:From: Bruno Wolff IIIDate: 2004-04-20 18:04:55
Subject: Re: Using SELECT WHERE
Previous:From: Tom LaneDate: 2004-04-20 17:11:09
Subject: Re: Start with -i

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group