Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c1MAb-0003RE-NR for pgsql-sql@arkaria.postgresql.org; Mon, 31 Oct 2016 23:39:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1c1MAa-0001kU-Dw for pgsql-sql@arkaria.postgresql.org; Mon, 31 Oct 2016 23:39:12 +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_2) (envelope-from ) id 1c1MAZ-0001kN-O8 for pgsql-sql@postgresql.org; Mon, 31 Oct 2016 23:39:11 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1c1MAW-0006lx-0A for pgsql-sql@postgresql.org; Mon, 31 Oct 2016 23:39:11 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id D79C8208B7; Mon, 31 Oct 2016 19:39:05 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute3.internal (MEProxy); Mon, 31 Oct 2016 19:39:05 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=aklaver.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=gaLJLJgjc2sNco8 DUUkiaa824ls=; b=BCIM9OmgO6ILUvDhFauRADj346SaHN/NgbC1A1R1V8AVXpF vceq3A4Tblf8lutmMvtCpcSxkJaVHkBqLpbCozqlVVfhebVOFQnRGlZPikBjIdW6 mFUSiUgB2XnLn830MzoRfcX06MTJAUKJzGmGLgDfJ7TPrTMKL9EQDr0NTQ7g= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= smtpout; bh=gaLJLJgjc2sNco8DUUkiaa824ls=; b=ESywRxAuFqxjgu+R7tB6 0OwBWKeazdcF2ow7rQ/wW/5OfkHD3ukbEwlth8UezILIv76szDyotSHi+PuEqfCD HJu5Dv32vApl3IizqUlswshMJTM5W/YMd4hiPFAYz+Wz5L2O1H0SZ/aapjGn674J EpYOFdSKgLyPx1xWgauxbu8= X-ME-Sender: X-Sasl-enc: 9j2at2yX6rkovpH48Yw4MhJ002aF0C2H5yWOJbBjAglh 1477957144 Received: from killi.site (c-73-225-242-52.hsd1.wa.comcast.net [73.225.242.52]) by mail.messagingengine.com (Postfix) with ESMTPA id EAEF5F29D1; Mon, 31 Oct 2016 19:39:00 -0400 (EDT) Subject: Re: Why does the PL/pgSQL compiler do this? To: Michael Moore , "David G. Johnston" References: Cc: postgres list From: Adrian Klaver Message-ID: <0520e6e1-8708-f58a-af0b-5624df7d01cf@aklaver.com> Date: Mon, 31 Oct 2016 16:38:54 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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 10/31/2016 04:32 PM, Michael Moore wrote: > I'm still a bit confused. If I replace the ROLLBACK; command with > ELEPHANT; the result is a syntax error. Why doesn't ROLLBACK; produce > the same error since it is not valid in the LANGUAGE plpgsql. I > understand that "ROLLBACK TO SAVEPOINT" IS valid. But it's not the same > thing. I am guessing this: https://www.postgresql.org/docs/9.5/static/plpgsql-implementation.html " A disadvantage is that errors in a specific expression or command cannot be detected until that part of the function is reached in execution. (Trivial syntax errors will be detected during the initial parsing pass, but anything deeper will not be detected until execution.)" ROLLBACK might actually be valid at some point, ELEPHANT will not so it caught in the trivial error stage. > > On Mon, Oct 31, 2016 at 3:55 PM, Michael Moore > wrote: > > Cool, thanks David, I'll give it a read. > > > On Mon, Oct 31, 2016 at 3:24 PM, David G. Johnston > > wrote: > > On Mon, Oct 31, 2016 at 3:13 PM, Michael Moore > >wrote: > > Here is the complete function, but all you need to look at > is the exception block. (I didn't write this code) :-) I > will ask the question after the code. > ​[...]​ > > RETURN TRUE; > > EXCEPTION WHEN OTHERS THEN > > RAISE EXCEPTION '% %', SQLERRM, SQLSTATE; > > ROLLBACK; > > RETURN FALSE; > > END; > > $BODY$ > > LANGUAGE plpgsql VOLATILE > > COST 100; > > > So, here is the question. Why does the compiler not catch: > > 1) ROLLBACK; is not a valid PL/pgSQL command > > > R > ​eading section ​41.10.2 at the linked page should answer this part. > > https://www.postgresql.org/docs/current/static/plpgsql-implementation.html > > > > 2) ROLLBACK; and RETURN FALSE; can never be reached > > > > Similar to the above - though "static analysis" is yet a step > beyond even what the syntax checking skipping covered above > would reveal. > > ​David J.​ > > > -- Adrian Klaver adrian.klaver@aklaver.com -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql