Thread: Trapping PL/Perl spi_query_exec errors

Trapping PL/Perl spi_query_exec errors

From
"Worky Workerson"
Date:
This is probably a really basic question, but how do I trap when
spi_query_exec returns an error in PL/Perl?  I would expect to be able
to use the return value to determine an error condition, however I get
the message:

ERROR:  error from Perl function: relation "foo" does not exist at line 7.

where line 7 looks like:

my $rv = spi_query_exec('select count(*) from foo');

Alternatively, I would expect to be able to trap it with eval, however
the trusted PL/Perl does not support eval.

Thanks!

Re: Trapping PL/Perl spi_query_exec errors

From
Tom Lane
Date:
"Worky Workerson" <worky.workerson@gmail.com> writes:
> This is probably a really basic question, but how do I trap when
> spi_query_exec returns an error in PL/Perl?

I think you don't, without using plperlu :-(.  Unless perhaps recent
Perls have added an error trapping construct that's separate from eval?

            regards, tom lane

Re: Trapping PL/Perl spi_query_exec errors

From
"Greg Sabino Mullane"
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


"Worky Workerson" <worky.workerson@gmail.com> wrote:
> This is probably a really basic question, but how do I trap when
> spi_query_exec returns an error in PL/Perl?

Tom Lane replied:
> I think you don't, without using plperlu :-(.  Unless perhaps recent
> Perls have added an error trapping construct that's separate from eval?

Tom is right, you need plperlu if you want to do this. Or be more careful
in your function by (for example) querying the pg_class table to see if
the table exists. Another alternative is to have pl/perlu do all the
"heavy lifting", and make some more limited wrapper functions in pl/perl.
And for the sake of the archives, it is "spi_exec_query" not "spi_query_exec".

- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200611230659
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8


-----BEGIN PGP SIGNATURE-----

iD8DBQFFZY2yvJuQZxSWSsgRAid1AKCBbLpjAYK/MMpQPiDBKapoOAIqygCfTrme
pDZrkflT0LLUvdlbWDxCoe0=
=OT2k
-----END PGP SIGNATURE-----