Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZG0Cc-0006dP-Mu for pgsql-sql@arkaria.postgresql.org; Fri, 17 Jul 2015 07:37:02 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZG0Cb-00019Z-Uz for pgsql-sql@arkaria.postgresql.org; Fri, 17 Jul 2015 07:37:01 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZG0Cb-000190-6X for pgsql-sql@postgresql.org; Fri, 17 Jul 2015 07:37:01 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZG0CY-0002ER-87 for pgsql-sql@postgresql.org; Fri, 17 Jul 2015 07:36:59 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id DE22E20B2D for ; Fri, 17 Jul 2015 03:36:56 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Fri, 17 Jul 2015 03:36:56 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=imap.cc; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=xEdyvdpG3xp6YcKXfH5B9RtshwU=; b=idH596 kz69sjfAcSzA1bScFFC1ONFFGqsZ40TDbROc/wpWX5JFNcPQt4aJqAJldeMxys8g qOipJ9BRJItHZ05DR0ywKveq5SOo8jB0/xrRH5k+rUUJNhJQzTYt80e13807pTmn JPI4G3Em52FDWWUvmtPIzgVY6fMWagdOufB8o= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=xEdyvdpG3xp6YcK XfH5B9RtshwU=; b=f2Gjyt+bO9mY+wY3gGJxKaDcuigPxt7x5DzVelz1DRMACED xyKTXJwvzNEfSU+JkxvbcAF90VQml0WaRAbe98rlmcD9opPyqBe9oSjIc1ehZ1Yv yKzNY/qYLvZrmkP8erLPCQWUGjuLgCbtmSL+7GA24RxgVf0Bry0QkmFjF9WE= X-Sasl-enc: PzjVzZEavFrLpX/93SMxrmYtR3ymIIYIQxAJSqBq2GCd 1437118616 Received: from [192.168.1.23] (unknown [195.91.155.97]) by mail.messagingengine.com (Postfix) with ESMTPA id 56F0B680214; Fri, 17 Jul 2015 03:36:56 -0400 (EDT) Message-ID: <55A8B097.8000303@imap.cc> Date: Fri, 17 Jul 2015 10:36:55 +0300 From: Alexey Bashtanov User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Alex Ignatov , pgsql-sql@postgresql.org Subject: Re: User defined exceptions References: <55A669CA.3070302@postgrespro.ru> In-Reply-To: <55A669CA.3070302@postgrespro.ru> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) 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 On 15.07.2015 17:10, Alex Ignatov wrote: > 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? Hello Alex, The following workaround could be used: do $$ begin raise exception using errcode = exception_aaa(); exception when others then if sqlstate = exception_aaa() then raise notice 'got exception %',sqlstate; else raise; --reraise end if; end; $$ Not sure if its performance is the same as in simple exception catch, maybe it would degrade. Best Regards, Alexey Bashtanov -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql