Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 95365632C84 for ; Fri, 23 Oct 2009 07:59:51 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 71007-07 for ; Fri, 23 Oct 2009 10:59:34 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by mail.postgresql.org (Postfix) with ESMTP id 6DCA0632283 for ; Fri, 23 Oct 2009 07:59:40 -0300 (ADT) Received: from localhost (access [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 541281E0441; Fri, 23 Oct 2009 18:59:37 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (access.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id uoxeDgefa1fF; Fri, 23 Oct 2009 18:59:35 +0800 (WST) Received: from [10.1.1.5] (124-169-36-119.dyn.iinet.net.au [124.169.36.119]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id 385191E0440; Fri, 23 Oct 2009 18:59:35 +0800 (WST) Message-ID: <4AE18C96.8000007@postnewspapers.com.au> Date: Fri, 23 Oct 2009 18:59:34 +0800 From: Craig Ringer User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Pavel Stehule CC: maboyz , pgsql-sql@postgresql.org Subject: Re: @@Error equivalent in Postgresql References: <25995788.post@talk.nabble.com> <162867790910211027k3daa588bwbd31d4ce8de23eb8@mail.gmail.com> <25998338.post@talk.nabble.com> <162867790910211932n5772f2a5ge43c3dcd45662316@mail.gmail.com> In-Reply-To: <162867790910211932n5772f2a5ge43c3dcd45662316@mail.gmail.com> X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.361 tagged_above=-10 required=5 tests=AWL=0.238, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200910/118 X-Sequence-Number: 33317 Pavel Stehule wrote: > So the > programming based on returning state codes is very obsolete, and > little bit difficult. You can emulate, but any protected block creates > inner transaction and this should negative effect on speed - and it > are some lines more. I'd like to second and emphasise this. Attempting to use return codes will cause you unnecessary grief. It might be worth it to maintain compatibility in other code between Pg and MS-SQL, but I'm not convinced - there are enough other differences that you'll probably need to maintain fairly different versions of the functions anyway. In many cases (mainly where no flow control is required) your T-SQL functions can become simple SQL functions anyway. I suspect in the long run you'll be better off handling errors by letting exceptions bubble up so that the caller can handle it or let it bubble up in turn. The exception will include an informative error code. You can then get that error code via exception information if you trap the exception in PL/PgSQL or via your application driver interface (JDBC/ODBC/etc) as the SQLSTATE if it bubbles up to a top-level statement. I've found PostgreSQL's exception-based error handling a real life-saver, especially when working with programming languages that also use exceptions. When I'm working in Java, for example, a sanity check deep in some PL/PgSQL function may raise an exception that propagates through to the top-level SQL statement, causing the JDBC driver to throw a Java SQLException that in turn propagates up to code that's in a position to do something about the problem. -- Craig Ringer