dbTalk Databases Forums  

Re: Using SELECT WHERE

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Re: Using SELECT WHERE in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Tom Lane
 
Posts: n/a

Default Re: Using SELECT WHERE - 04-20-2004 , 01:00 PM






Michal Lijowski <michal (AT) cvu (DOT) wustl.edu> writes:
Quote:
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

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.