pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bryn Llewellyn <bryn@yugabyte.com>
To: pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: PL/pgSQL: « arr[j].a := v » works fine in PG Version 14.4, fails to compile in Version 11.2. Which version brought the fix?
Date: Mon, 25 Jul 2022 10:34:31 -0700
Message-ID: <0ABA97CF-ADA4-43D5-A2DB-38A705561494@yugabyte.com> (raw)

I copied my testcase at the end. It runs OK and produces the output that I expect using PG Version 14.4. But using Version 11.9 (and earlier 11 sub-versions), it fails to compile with this error:

syntax error at or near "."
lhs[j].a := rhs[j].a;
      ^
If I comment out the "Ideal approach" loop, then it runs fine in PG 11 and produces the same output as the "Ideal approach" does in PG 14,

I looked at the Release Notes for each of Versions 14, 13, and 12:

https://www.postgresql.org/docs/12/release-12-1.html <https://www.postgresql.org/docs/12/release-12-1.html;
https://www.postgresql.org/docs/13/release-13-1.html <https://www.postgresql.org/docs/13/release-13-1.html;
https://www.postgresql.org/docs/14/release-14-1.html <https://www.postgresql.org/docs/14/release-14-1.html;

I searched in the page for "array". But there were no relevant hits on any of those three pages.

Can anybody tell me which PG release brought the improvement?

p.s., I'm asking because YugabyteDB still uses the PG 11.2 SQL processing code. I'm promised that fairly soon a new YugabyteDB version will use the PG 13 SQL processing code. I'm hoping that, then, I'll be able to retire my workaround.

--------------------------------------------------------------------------------

create type t as (a text, b text);

create function f()
  returns table(z text)
  language plpgsql
as $body$
declare
  lhs          t[] not null := array[('??', '??'), ('??', '??'), ('??', '??')];
  rhs constant t[] not null := array[('a1', 'b1'), ('a2', 'b2'), ('a3', 'b3')];

  r            t   not null :=       ('??', '??');
begin
  for j in 1..3 loop
    z := rhs[j].a||', '||rhs[j].b;    return next;
  end loop;

  -- Workaround
  for j in 1..3 loop
    r := rhs[j];
    r.a := rhs[j].a;
    r.b := rhs[j].b;
    lhs[j] := r;
  end loop;

  -- Ideal approach.
  for j in 1..3 loop
    lhs[j].a := rhs[j].a;
    lhs[j].b := rhs[j].b;
  end loop;

  z := '';                            return next;
  for j in 1..3 loop
    z := lhs[j].a||', '||lhs[j].b;    return next;
  end loop;
end;
$body$;

select z from f();

view thread (3+ messages)  latest in thread

Message-ID: <0ABA97CF-ADA4-43D5-A2DB-38A705561494@yugabyte.com>
Permalink:  ../0ABA97CF-ADA4-43D5-A2DB-38A705561494@yugabyte.com/
Also on:    postgresql.org/message-id/0ABA97CF-ADA4-43D5-A2DB-38A705561494@yugabyte.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: bryn@yugabyte.com
  Subject: Re: PL/pgSQL: « arr[j].a := v » works fine in PG Version 14.4, fails to compile in Version 11.2. Which version brought the fix?
  In-Reply-To: <0ABA97CF-ADA4-43D5-A2DB-38A705561494@yugabyte.com>
  References: <0ABA97CF-ADA4-43D5-A2DB-38A705561494@yugabyte.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox