From: Alex Lai <mlai@sesda3.com>
To: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Unable to handle error in plperl
Date: Wed, 10 Jul 2013 16:36:51 -0400
Message-ID: <51DDC5E3.6090405@sesda3.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Dear all,
I have a situation. I am unable to pass control back to the function
once it hit the "undefined_column" error code.
I am not sure there's a way to return '123' instead exit from the function.
Here is my code
CREATE OR REPLACE FUNCTION foo() RETURNS text as $$
my $sql = "";
my $status = "";
my $r = "";
$sql = 'SELECT non_exist_column from a_table limit 1';
eval { spi_exec_query($sql);};
if ($@) {
$status = 'invalid: '.$@;
elog(ERROR, $status);
return '123';
} else {
$status = 'valid';
}
return $status;
$$ LANGUAGE plperl;
When I run it
select foo();
ERROR: invalid: column "non_exist_column" does not exist at line 6.
CONTEXT: PL/Perl function "foo"
When I select from the valid column
CREATE OR REPLACE FUNCTION foo() RETURNS text as $$
my $sql = "";
my $status = "";
my $r = "";
$sql = 'SELECT exist_column from a_table limit 1';
eval { spi_exec_query($sql);};
if ($@) {
$status = 'invalid: '.$@;
elog(ERROR, $status);
return '123';
} else {
$status = 'valid';
}
return $status;
$$ LANGUAGE plperl;
When I run it
select foo();
foo
----------
valid
(1 row)
--
Best regards,
Alex Lai
OMI SIPS DBA ADNET Systems , Inc.
7515 Mission Drive,
Suite A100 Lanham, MD 20706
301-352-4657 (phone)
301-352-0437 (fax)
mlai@sesda3.com
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: mlai@sesda3.com
Subject: Re: Unable to handle error in plperl
In-Reply-To: <51DDC5E3.6090405@sesda3.com>
References: <51DDC5E3.6090405@sesda3.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox