Re: Trapping errors from pl/perl (trigger) functions - Mailing list pgsql-general

From Michael Fuhr
Subject Re: Trapping errors from pl/perl (trigger) functions
Date
Msg-id 20070701215330.GA8778@winnie.fuhr.org
Whole thread Raw
In response to Re: Trapping errors from pl/perl (trigger) functions  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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

pgsql-general by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: [pgsql-general] In memory tables/databases
Next
From: Wiebe Cazemier
Date:
Subject: Re: Trapping errors from pl/perl (trigger) functions