Re: Re: « The PL/pgSQL interpreter parses the function's source text and produces an internal binary instruction tree... » - Mailing list pgsql-general

From Tom Lane
Subject Re: Re: « The PL/pgSQL interpreter parses the function's source text and produces an internal binary instruction tree... »
Date
Msg-id 3603324.1659060242@sss.pgh.pa.us
Whole thread Raw
In response to Re: « The PL/pgSQL interpreter parses the function's source text and produces an internal binary instruction tree... »  (Christophe Pettus <xof@thebuild.com>)
Responses Re: « The PL/pgSQL interpreter parses the function's source text and produces an internal binary instruction tree... »  (Bryn Llewellyn <bryn@yugabyte.com>)
List pgsql-general
Christophe Pettus <xof@thebuild.com> writes:
>> On Jul 28, 2022, at 18:04, Bryn Llewellyn <bryn@yugabyte.com> 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



pgsql-general by date:

Previous
From: Bryn Llewellyn
Date:
Subject: Re: « The PL/pgSQL interpreter parses the function's source text and produces an internal binary instruction tree... »
Next
From: Christophe Pettus
Date:
Subject: Re: « The PL/pgSQL interpreter parses the function's source text and produces an internal binary instruction tree... »