X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 566C43ABDEA for ; Tue, 28 Dec 2004 22:55:24 +0000 (GMT) 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 77576-05 for ; Tue, 28 Dec 2004 22:55:09 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id E59A43AC11E for ; Tue, 28 Dec 2004 22:50:37 +0000 (GMT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.1/8.13.1) with ESMTP id iBSMoTkC030497 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 28 Dec 2004 15:50:32 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.1/8.13.1) with ESMTP id iBSMoTxc068090; Tue, 28 Dec 2004 15:50:29 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.1/8.13.1/Submit) id iBSMoSG9068089; Tue, 28 Dec 2004 15:50:28 -0700 (MST) (envelope-from mfuhr) Date: Tue, 28 Dec 2004 15:50:28 -0700 From: Michael Fuhr To: Robert Wimmer Cc: pgsql-interfaces@postgresql.org Subject: Re: type cast/validation functions Message-ID: <20041228225028.GA68003@winnie.fuhr.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.002 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200412/53 X-Sequence-Number: 5223 On Tue, Dec 28, 2004 at 09:50:09PM +0000, Robert Wimmer wrote: > > as i posted a few weeks ago, it is a handicap for me writing client side > appliciations with postgres, that you cant catch errorcodes - especially > after type casts. so you have to rewrite type check functions for every > client system. Would 8.0's subtransactions, in particular PL/pgSQL's new error trapping construct, solve your problem? CREATE OR REPLACE FUNCTION text2date(TEXT) RETURNS DATE AS $$ DECLARE dat DATE; BEGIN BEGIN dat := CAST($1 AS DATE); EXCEPTION WHEN invalid_datetime_format OR datetime_field_overflow THEN RAISE INFO 'Bogus date ''%'', returning NULL', $1; dat := NULL; END; RETURN dat; END; $$ LANGUAGE plpgsql IMMUTABLE STRICT; > if someone is interested in my solution there is a demo and a short > description available at > > http://www.wiro.co.at/postgres/test/demo_en.php This link returns 404 Not Found -- the correct link appears to be: http://www.wiro.co.at/postgres/demo_en.php -- Michael Fuhr http://www.fuhr.org/~mfuhr/