Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Ux1n8-0006ea-EF for pgsql-bugs@arkaria.postgresql.org; Wed, 10 Jul 2013 21:19:14 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Ux1n7-0004gx-Nr for pgsql-bugs@arkaria.postgresql.org; Wed, 10 Jul 2013 21:19:13 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Ux18G-0004sW-Fy for pgsql-bugs@postgresql.org; Wed, 10 Jul 2013 20:37:00 +0000 Received: from franklin.sesda3.com ([4.31.164.37]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Ux18C-0007XT-36 for pgsql-bugs@postgresql.org; Wed, 10 Jul 2013 20:36:59 +0000 Received: from localhost (localhost [127.0.0.1]) by franklin.sesda3.com (Postfix) with ESMTP id F0B20E459F for ; Wed, 10 Jul 2013 16:36:54 -0400 (EDT) X-DSPAM-Result: Innocent X-DSPAM-Class: Innocent X-DSPAM-Confidence: 0.83 X-DSPAM-Probability: 0.0000 X-DSPAM-Signature: N/A X-Virus-Scanned: amavisd-new at X-Spam-Flag: NO X-Spam-Score: -3.9 X-Spam-Level: X-Spam-Status: No, score=-3.9 tagged_above=-10 required=6.6 tests=[ALL_TRUSTED=-1, BAYES_00=-1.9, DSPAM:Innocent=-1.000] autolearn=ham Received: from franklin.sesda3.com ([127.0.0.1]) by localhost (franklin.sesda3.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 33oAeJFkJgmc for ; Wed, 10 Jul 2013 16:36:54 -0400 (EDT) Received: from [192.168.200.162] (gs6064-ld-o-17.sesdawin.local [192.168.200.162]) by franklin.sesda3.com (Postfix) with ESMTPSA id 3F837E4194 for ; Wed, 10 Jul 2013 16:36:52 -0400 (EDT) Message-ID: <51DDC5E3.6090405@sesda3.com> Date: Wed, 10 Jul 2013 16:36:51 -0400 From: Alex Lai User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 MIME-Version: 1.0 To: "pgsql-bugs@postgresql.org" Subject: Unable to handle error in plperl Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 0.5 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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