Re: I need a SQL... - Mailing list pgsql-general

From Tom Lane
Subject Re: I need a SQL...
Date
Msg-id 26747.1063290361@sss.pgh.pa.us
Whole thread Raw
In response to Re: I need a SQL...  (Bjørn T Johansen <btj@havleik.no>)
Responses Re: I need a SQL...
List pgsql-general
=?ISO-8859-1?Q?Bj=F8rn?= T Johansen <btj@havleik.no> writes:
> Yes, I am sure, I just use copy-and-paste and I have double checked....
> I am running on 7.3.4 but that shouldn't make any difference?

It'll probably work better if you quote the zero.  Unquoted, you get
some weird textual comparison.  Compare:

regression=# explain select * from time_tbl where f1-f1 >= 0;
                       QUERY PLAN
--------------------------------------------------------
 Seq Scan on time_tbl  (cost=0.00..1.14 rows=3 width=8)
   Filter: (((f1 - f1))::text >= '0'::text)
(2 rows)

regression=# explain select * from time_tbl where f1-f1 >= '0';
                       QUERY PLAN
--------------------------------------------------------
 Seq Scan on time_tbl  (cost=0.00..1.12 rows=3 width=8)
   Filter: ((f1 - f1) >= '00:00'::interval)
(2 rows)

In "C" locale, the textual comparison accidentally manages to give
the desired answers, but in other locales it would not.

(Just another example of why implicit coercions to text are evil.)

            regards, tom lane

pgsql-general by date:

Previous
From: "Mattias Kregert"
Date:
Subject: Re: I need a SQL...
Next
From: Bjørn T Johansen
Date:
Subject: Re: I need a SQL...