Thread: catch runtime errors

catch runtime errors

From
"Robert Wimmer"
Date:
hi,

is there a possibility to catch runtime errors in pgplsql function ? i did
not  find anything about this in the docs. what i want to do is to check all
values in a database function before doing any uptates or inserts.

for example (psudo code)

CREATE FUNCTION insert_xxx(TEXT,TEXT) RETURNS INT AS '
DECLARE id INTEGER;
  d DATE;
BEGIN
  -- check if $1 is integer
  id := CAST($1 AS INT);
  IF xxxError THEN RETURN -1; END IF;
  -- check if $2 is date
  d := CAST($2 AS DATE);
  IF xxxError THEN RETURN -2; END IF;
  ...
  RETURN 0;
END; '
......

i want to avoid to write different conversion tools for maybe php or java or
c or even VB. there is a function somewhere inside psql thats checking it -
because it causes a runtime error if something is wrong - why reinvent the
wheel (4 times!)  ?

bye and thanks

sepp

_________________________________________________________________
Schaffen Sie das Platzproblem in Ihrem E-Mail-Konto für immer aus der Welt!
http://join.msn.com/?pgmarket=de-at&DI=1031&XAPID=1581


Re: catch runtime errors

From
Tom Lane
Date:
"Robert Wimmer" <seppwimmer@hotmail.com> writes:
> is there a possibility to catch runtime errors in pgplsql function ?

As of PG 8.0, yes; before that, no.

            regards, tom lane