Re: Trapping errors from pl/perl (trigger) functions

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Wiebe Cazemier <halfgaar(at)gmx(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: Trapping errors from pl/perl (trigger) functions
Date: 2007-07-01 21:53:30
Message-ID: 20070701215330.GA8778@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, Jul 01, 2007 at 03:50:09PM -0400, Tom Lane wrote:
> IMHO the real problem with both RAISE and the plperl elog command
> is there's no way to specify which SQLSTATE to throw. In the case
> of the elog command I think you just get a default.

That default is XX000 (internal_error):

test=> create function foo()
test-> returns void
test-> language plperl
test-> as $_$
test$> elog(ERROR, 'test error');
test$> $_$;
CREATE FUNCTION
test=> \set VERBOSITY verbose
test=> select foo();
ERROR: XX000: error from Perl function: test error at line 2.
LOCATION: plperl_call_perl_func, plperl.c:1076

The code around plperl.c:1076 is

/* XXX need to find a way to assign an errcode here */
ereport(ERROR,
(errmsg("error from Perl function: %s",
strip_trailing_ws(SvPV(ERRSV, PL_na)))));

I don't see any relevant TODO items. Would something like the
following be appropriate?

* Allow RAISE and its analogues to set SQLSTATE.

--
Michael Fuhr

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Wiebe Cazemier 2007-07-01 22:07:14 Re: Trapping errors from pl/perl (trigger) functions
Previous Message Alvaro Herrera 2007-07-01 21:43:41 Re: [pgsql-general] In memory tables/databases