Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZFNOE-0007Kd-9d for pgsql-sql@arkaria.postgresql.org; Wed, 15 Jul 2015 14:10:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZFNOD-00069t-SC for pgsql-sql@arkaria.postgresql.org; Wed, 15 Jul 2015 14:10:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZFNOD-00069c-Hg for pgsql-sql@postgresql.org; Wed, 15 Jul 2015 14:10:25 +0000 Received: from newmail.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZFNO6-00069R-G5 for pgsql-sql@postgresql.org; Wed, 15 Jul 2015 14:10:24 +0000 Received: from [127.0.0.1] (unknown [192.168.27.1]) by mail.postgrespro.ru (Postfix) with ESMTPSA id B382521C21A7 for ; Wed, 15 Jul 2015 17:10:16 +0300 (MSK) Message-ID: <55A669CA.3070302@postgrespro.ru> Date: Wed, 15 Jul 2015 17:10:18 +0300 From: Alex Ignatov User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: User defined exceptions Content-Type: multipart/alternative; boundary="------------060007010003030505030705" X-Antivirus: avast! (VPS 150715-0, 15.07.2015), Outbound message X-Antivirus-Status: Clean X-Pg-Spam-Score: -1.6 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org This is a multi-part message in MIME format. --------------060007010003030505030705 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hello all! Trying to emulate "named" user defined exception with: CREATE OR REPLACE FUNCTION exception_aaa () RETURNS text AS $body$ BEGIN return 31234; END; $body$ LANGUAGE PLPGSQL SECURITY DEFINER ; do $$ begin raise exception using errcode=exception_aaa(); exception when sqlstate exception_aaa() then raise notice 'got exception %',sqlstate; end; $$ Got: ERROR: syntax error at or near "exception_aaa" LINE 20: sqlstate exception_aaa() I looks like "when sqlstate exception_aaa()" doesn't work. How can I catch exception in this case? -- Alex Ignatov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus --------------060007010003030505030705 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit Hello all!
Trying to emulate "named" user defined exception with:
CREATE OR REPLACE FUNCTION exception_aaa ()  RETURNS text AS $body$
BEGIN
   return 31234;     
END;
$body$
LANGUAGE PLPGSQL
SECURITY DEFINER
;

do $$
begin
   raise exception using errcode=exception_aaa();
exception
   when  sqlstate exception_aaa()
   then
      raise notice 'got exception %',sqlstate;
end;
$$
 
Got:

ERROR:  syntax error at or near "exception_aaa"
LINE 20: sqlstate exception_aaa()

I looks like "when  sqlstate exception_aaa()" doesn't work.

How can I catch exception in this case?
-- 
Alex Ignatov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company




Avast logo

This email has been checked for viruses by Avast antivirus software.
www.avast.com


--------------060007010003030505030705--