From: | Alex Lai <mlai(at)sesda3(dot)com> |
---|---|
To: | "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org> |
Subject: | Unable to handle error in plperl |
Date: | 2013-07-10 20:36:51 |
Message-ID: | 51DDC5E3.6090405@sesda3.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-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(at)sesda3(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Josh Kupershmidt | 2013-07-10 21:42:33 | Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist |
Previous Message | jaroslav.potapov | 2013-07-10 19:07:54 | BUG #8293: There are no methods to convert json scalar text to text in v9.3 beta2 |