From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | robert(at)webtent(dot)com |
Cc: | Jeff Davis <pgsql(at)j-davis(dot)com>, PostgreSQL <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Test text value as interval |
Date: | 2008-02-08 02:13:49 |
Message-ID: | 20725.1202436829@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Robert Fitzpatrick <lists(at)webtent(dot)net> writes:
> Yes, this looks like it might work, thanks! But not sure which condition
> to look for or if I'm doing this correctly. I tried syntax_error
> condition, but I'm still receiving the same cast error trying this in a
> trigger function...
SYNTAX_ERROR is for SQL-command syntax errors. What you're after is
a data exception. Here's how to figure out what you want: in psql,
provoke the error and find out the SQLSTATE number.
regression=# \set VERBOSITY verbose
regression=# select 'foo'::text::interval;
ERROR: 22007: invalid input syntax for type interval: "foo"
LOCATION: DateTimeParseError, datetime.c:3137
Now look up "22007" in the list of error codes
http://www.postgresql.org/docs/8.2/static/errcodes-appendix.html
and you'll find out it's "invalid_datetime_format".
Looking at the list, there are some other codes like
interval_field_overflow that you'll likely want to trap too.
In fact, if this is the *only* operation within the exception
block, maybe you should just do "when others", assuming that
the only possible cause of an error is bogus input data.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2008-02-08 02:16:48 | Re: How can exe files such as 'pg_dump' be called from stored functions? |
Previous Message | Robert Fitzpatrick | 2008-02-08 01:59:18 | Re: Test text value as interval |