Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oHFMK-000717-Ef for pgsql-general@arkaria.postgresql.org; Fri, 29 Jul 2022 02:04:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oHFMJ-0000CL-0X for pgsql-general@arkaria.postgresql.org; Fri, 29 Jul 2022 02:04:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oHFMI-0000BC-Lt for pgsql-general@lists.postgresql.org; Fri, 29 Jul 2022 02:04:10 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oHFMB-0001dt-Uv for pgsql-general@lists.postgresql.org; Fri, 29 Jul 2022 02:04:09 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 26T242Mo3603325; Thu, 28 Jul 2022 22:04:02 -0400 From: Tom Lane To: Christophe Pettus cc: Bryn Llewellyn , pgsql-general list Subject: Re: =?utf-8?Q?Re=3A_=C2=AB_The_PL/pgSQL_interpreter_parses_the_functi?= =?utf-8?Q?on=27s_source_text_and_produces_an_internal_binary_instruction_?= =?utf-8?Q?tree=2E=2E=2E_=C2=BB?= In-reply-to: <14BAC5B9-225E-49A8-A225-60C2F179E334@thebuild.com> References: <14BAC5B9-225E-49A8-A225-60C2F179E334@thebuild.com> Comments: In-reply-to Christophe Pettus message dated "Thu, 28 Jul 2022 18:23:30 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3603323.1659060242.1@sss.pgh.pa.us> Date: Thu, 28 Jul 2022 22:04:02 -0400 Message-ID: <3603324.1659060242@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Christophe Pettus writes: >> On Jul 28, 2022, at 18:04, Bryn Llewellyn wrote: >> Is this expected? > Yes. This isn't a bug. It's actually a feature: there are cases where it's useful that we don't do semantics checking on statements until they are reached. A trivial example is begin create table foo(...); insert into foo values(...); end; which would never work at all if we insisted on semantic validity of the INSERT before the CREATE is executed. Having said that, there are certainly aspects of what happens when in plpgsql that don't have a lot of justification other than being implementation artifacts. For instance, things that are certainly plpgsql variable names (e.g. the lefthand side of an assignment) are checked sooner than things that might not be (e.g. the righthand side). That's defensible on a couple of grounds but it undoubtedly leads to surprising results if you expect error conditions to be recognized left-to-right or anything like that. Of course, SQL commands themselves have to be analyzed in not particularly left-to-right order, and we don't get that many complaints about that. regards, tom lane