Re: type cast/validation functions

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Robert Wimmer <seppwimmer(at)hotmail(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: type cast/validation functions
Date: 2004-12-28 22:50:28
Message-ID: 20041228225028.GA68003@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

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/

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Robert Wimmer 2004-12-29 00:12:53 Re: type cast/validation functions
Previous Message Robert Wimmer 2004-12-28 21:50:09 type cast/validation functions