X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 5E599329C70 for ; Thu, 9 Sep 2004 15:23:19 +0100 (BST) 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 56460-01 for ; Thu, 9 Sep 2004 14:23:10 +0000 (GMT) Received: from poweredge.attiksystem.ch (adsl-soholight-4-c59-p029.vtx.ch [212.147.59.29]) by svr1.postgresql.org (Postfix) with ESMTP id 8A040329C67 for ; Thu, 9 Sep 2004 15:23:10 +0100 (BST) MIME-Version: 1.0 Subject: Datetime conversion in WHERE clause Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-MimeOLE: Produced By Microsoft Exchange V6.0.6487.1 content-class: urn:content-classes:message Date: Thu, 9 Sep 2004 16:23:10 +0200 Message-ID: <6C0CF58A187DA5479245E0830AF84F420803F0@poweredge.attiksystem.ch> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Datetime conversion in WHERE clause Thread-Index: AcSWeIh0NYCgHEBETreDd/CeOFtmMw== From: "Philippe Lang" To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/62 X-Sequence-Number: 18908 Hello, I'm converting a varchar to a date in a search routine which looks like: ---------------------------------------------- CREATE FUNCTION public.search_data(varchar) RETURNS SETOF foo1 AS ' SELECT DISTINCT foo1.* FROM foo1 LEFT JOIN foo2 ON foo2.fk =3D foo1.pk WHERE lower(foo1.text_data1) LIKE lower($1) OR lower(foo1.text_data2) LIKE lower($1) OR foo1.date_data =3D $1::text:date OR lower(foo2.text_data3) LIKE lower($1) OR lower(foo2.text_data4) LIKE lower($1) ' LANGUAGE 'sql' VOLATILE; ---------------------------------------------- The problem with the ::text::date conversion is that the whole function fails if the search string parameter cannot be converted into a valid date, like 'test%', for example, which is valid for the other text fields. Is there a way to force the date conversion to fail sliently, and simply return a null in case the parameter is not a valid date? Thanks Philippe Lang