Re: Test text value as interval - Mailing list pgsql-general

From Jeff Davis
Subject Re: Test text value as interval
Date
Msg-id 1202432316.20053.96.camel@dogma.ljc.laika.com
Whole thread Raw
In response to Test text value as interval  (Robert Fitzpatrick <lists@webtent.net>)
Responses Re: Test text value as interval
List pgsql-general
On Thu, 2008-02-07 at 19:37 -0500, Robert Fitzpatrick wrote:
> Been searching for a way to do this, but haven't found what I was hoping
> to find. Is there any way in pl/pgsql to test a text value to see if it
> would be a valid interval without having to try and store in a field? In
> a trigger, I'd like to test a NEW text type field. Right now, I have
> just the following to generate an error...
>
> test := NEW.textfield::interval;
>
> I'd like to test the field and RAISE EXCEPTION if not valid interval.

Trap the error and do what you want with it:

http://www.postgresql.org/docs/8.3/static/plpgsql-control-
structures.html#PLPGSQL-ERROR-TRAPPING

Although: why do you want to generate your own error? It seems like it
would probably be about the same as the error produced by the casting
failure.

Regards,
    Jeff Davis


pgsql-general by date:

Previous
From: Robert Fitzpatrick
Date:
Subject: Test text value as interval
Next
From: "rkmr.em@gmail.com"
Date:
Subject: password option in pg_dumpall