Re: Text->Date conversion in a WHERE clause

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Collin Peters <cadiolis(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Text->Date conversion in a WHERE clause
Date: 2005-10-12 22:20:47
Message-ID: 4703.1129155647@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Collin Peters <cadiolis(at)gmail(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Scott Marlowe 2005-10-12 22:24:35 Re: pg, mysql comparison with "group by" clause
Previous Message Greg Stark 2005-10-12 22:01:18 Re: Text->Date conversion in a WHERE clause