Re: Text->Date conversion in a WHERE clause - Mailing list pgsql-sql

From Tom Lane
Subject Re: Text->Date conversion in a WHERE clause
Date
Msg-id 4703.1129155647@sss.pgh.pa.us
Whole thread Raw
In response to Text->Date conversion in a WHERE clause  (Collin Peters <cadiolis@gmail.com>)
List pgsql-sql
Collin Peters <cadiolis@gmail.com> writes:
> WHERE cust3 <> ''
> AND cust3::text::timestamp > CURRENT_DATE - interval '1 month'

> This results in the error 'ERROR:  date/time field value out of range:
> "052-44-5863"'.  Now that is obviously not a valid date.... but there
> is actually more to the where clause and the first part of it excludes
> all rows where the user is not even the correct type, so the row which
> includes the field '052-44-5863' should really not even be checked.

Your mistake is in supposing that WHERE clauses are guaranteed to be
evaluated in a particular order.  Such guarantees are made only for a
very few specific constructs such as CASE.  See
http://www.postgresql.org/docs/8.0/static/sql-expressions.html#SYNTAX-EXPRESS-EVAL
        regards, tom lane


pgsql-sql by date:

Previous
From: Greg Stark
Date:
Subject: Re: Text->Date conversion in a WHERE clause
Next
From: Scott Marlowe
Date:
Subject: Re: pg, mysql comparison with "group by" clause