Re: Select gives the wrong results - Mailing list pgsql-general

From Alban Hertroys
Subject Re: Select gives the wrong results
Date
Msg-id 43143C80.7060306@magproductions.nl
Whole thread Raw
In response to Select gives the wrong results  (Crystle Numan <crys@guidedvision.com>)
List pgsql-general
Crystle Numan wrote:
> Dear all:
>
> I am fairly knowledgeable about PostgreSQL but this behaviour is
> stumping me. Any help would be wonderful. If you think it is a bug, let
> me now and I'll file one.
>
> (select values in DB (date stamps) between Jan 1, 2000 and Jan 1, 2005,
> no results)
>
> db_name=# SELECT * from person_detail WHERE field='2' AND
> value>'946702800' AND value<'1104555600';
>  id | person | field | value
> ----+--------+-------+-------
> (0 rows)

You are comparing strings, which is not quite the same as a numerical
comparison. The above range is empty, as '9...' > '1...' (even though
the left string is shorter).

Either compare numbers, or left pad your left string with zeroes until
it's the same length as the right string.

--
Alban Hertroys
alban@magproductions.nl

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
    7500 AK Enschede

//Showing your Vision to the World//

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: psql from Linux script
Next
From: Clodoaldo Pinto
Date:
Subject: Re: update functions locking tables