pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedUnable to handle error in plperl
4+ messages / 3 participants
[nested] [flat]
* Unable to handle error in plperl
@ 2013-07-10 20:36 Alex Lai <mlai@sesda3.com>
0 siblings, 1 reply; 4+ messages in thread
From: Alex Lai @ 2013-07-10 20:36 UTC (permalink / raw)
To: 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@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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Unable to handle error in plperl
@ 2013-07-11 15:47 Alex Hunsaker <badalex@gmail.com>
parent: Alex Lai <mlai@sesda3.com>
0 siblings, 1 reply; 4+ messages in thread
From: Alex Hunsaker @ 2013-07-11 15:47 UTC (permalink / raw)
To: Alex Lai <mlai@sesda3.com>; +Cc: pgsql-bugs
On Wed, Jul 10, 2013 at 2:36 PM, Alex Lai <mlai@sesda3.com> wrote:
> 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);
Its this bit here that is tripping you up. Perhaps you meant
elog(INFO, ...) or something?
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Unable to handle error in plperl
@ 2013-07-15 11:56 Ming Lai <mlai@sesda3.com>
parent: Alex Hunsaker <badalex@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Ming Lai @ 2013-07-15 11:56 UTC (permalink / raw)
To: Alex Hunsaker <badalex@gmail.com>; +Cc: pgsql-bugs
I know how elog works. elog only show the status, but it does not allow me to execute another query when the current query fails because one of the invalid column was specified.
Alex Lai
----- Original Message -----
From: "Alex Hunsaker" <badalex@gmail.com>
To: "Alex Lai" <mlai@sesda3.com>
Cc: pgsql-bugs@postgresql.org
Sent: Thursday, July 11, 2013 11:47:04 AM
Subject: Re: [BUGS] Unable to handle error in plperl
On Wed, Jul 10, 2013 at 2:36 PM, Alex Lai <mlai@sesda3.com> wrote:
> 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);
Its this bit here that is tripping you up. Perhaps you meant
elog(INFO, ...) or something?
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Unable to handle error in plperl
@ 2013-07-15 19:22 Alex Hunsaker <badalex@gmail.com>
parent: Ming Lai <mlai@sesda3.com>
0 siblings, 0 replies; 4+ messages in thread
From: Alex Hunsaker @ 2013-07-15 19:22 UTC (permalink / raw)
To: Ming Lai <mlai@sesda3.com>; +Cc: pgsql-bugs
On Mon, Jul 15, 2013 at 5:56 AM, Ming Lai <mlai@sesda3.com> wrote:
> I know how elog works. elog only show the status, but it does not allow me to execute another query when the current query fails because one of the invalid column was specified.
Hrm? Im not sure what you mean. If you elog(ERROR) outside of eval the
current transaction will be aborted. Thats why I suggested doing
elog(INFO) instead. The below example works fine for me. Perhaps you
can highlight exactly what you think it broken so I can understand?
=> begin;
BEGIN
=> create table a_table (a_column int);
CREATE TABLE
=> 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: '.$@;
my $rv = spi_exec_query('SELECT true as col;');
return "$status\nQuery after error: ".$rv->{rows}[0]{'col'};
} else {
$status = 'valid';
}
return $status;
$$ LANGUAGE plperl;
CREATE FUNCTION
=> select foo();
foo
──────────────────────────────────────────────────────────────
invalid: column "non_exist_column" does not exist at line 6.↵
↵
Query after error: t
(1 row)
=> select true;
bool
──────
t
(1 row)
=> commit;
COMMIT
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2013-07-15 19:22 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-07-10 20:36 Unable to handle error in plperl Alex Lai <mlai@sesda3.com>
2013-07-11 15:47 ` Alex Hunsaker <badalex@gmail.com>
2013-07-15 11:56 ` Ming Lai <mlai@sesda3.com>
2013-07-15 19:22 ` Alex Hunsaker <badalex@gmail.com>
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