X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4E7F1D7E87 for ; Wed, 12 Oct 2005 17:59:31 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 28975-09 for ; Wed, 12 Oct 2005 20:59:25 +0000 (GMT) Received: from qproxy.gmail.com (qproxy.gmail.com [72.14.204.195]) by svr1.postgresql.org (Postfix) with ESMTP id 68098D7728 for ; Wed, 12 Oct 2005 17:59:26 -0300 (ADT) Received: by qproxy.gmail.com with SMTP id q11so71432qbq for ; Wed, 12 Oct 2005 13:59:27 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=sQpjStaGlMu3Fv2CerM4jXTzM4WfTKsjiLDh1YxRNuNZ2z/UhdZpvvZKvPxiRXyITlO2LBsXO+ePlfYoKnRFLqePQb7Pp6lcL1HQTZoImpEg7a1dXQ5FxCmqHNVk+nhqJq7RtEIxhGDOWEb65b/QKqZ8eFxdLKjPsymyH0VZxwM= Received: by 10.65.194.4 with SMTP id w4mr595770qbp; Wed, 12 Oct 2005 13:59:26 -0700 (PDT) Received: by 10.65.158.4 with HTTP; Wed, 12 Oct 2005 13:59:26 -0700 (PDT) Message-ID: Date: Wed, 12 Oct 2005 13:59:26 -0700 From: Collin Peters To: pgsql-sql@postgresql.org Subject: Text->Date conversion in a WHERE clause MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.024 required=5 tests=[RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200510/105 X-Sequence-Number: 22958 I have a table that has some columns which store 'custom' fields so the content varies according to the user that the row belongs to. For one of the groups of users the field is a date (the type of the field is 'text' though). I'm trying to perform a query where it only returns values in a certain date range so in the WHERE clause I have 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. My main confusion lies in the assumption I made that the offending row would not even be included as it should have already been discarded. Is this not the case? How can I overcome this problem? There appears to be no isDate() function in postgresql like there is in sql server. Regards, Collin Peters