Re: PL/pgSQL: Spurious 22P02 error on "select col into var" when col is user-defined type

From: Bryn Llewellyn <bryn(at)yugabyte(dot)com>
To: Tom Lane PostgreSQL <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, John W Higgins <wishdev(at)gmail(dot)com>
Cc: pgsql-general list <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: PL/pgSQL: Spurious 22P02 error on "select col into var" when col is user-defined type
Date: 2021-08-10 00:00:39
Message-ID: 0B8B7D5F-96C2-46B6-8050-37199598C002@yugabyte.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> tgl(at)sss(dot)pgh(dot)pa(dot)us wrote:
>
>> pavel(dot)stehule(at)gmail(dot)com writes:
>>
>> Some errors like this, but not this can be detected by plpgsql_check
>> https://www.google.com/url?q=https://github.com/okbob/plpgsql_check&source=gmail-imap&ust=1629148434000000&usg=AOvVaw3f9UAP7RvDPC2QKi3_4Mj0 - probably the heuristic for type
>> check is not complete.
>
> STRICTMULTIASSIGNMENT would detect most cases of this, except that the condition is checked too late. We'd need to count the fields
> *before* trying to assign values, not after.
>
> In the meantime, it does seem like the docs could be more explicit about this, and perhaps give an example showing the (x).* solution.

Tom, Pavel, and John, thanks for your quick responses. I've filed them all away and I'm hoping that I won't be caught out by this in the future.

It now seems to me to be odd, in the light of the explanations for why the naïve (PL/SQL-style) syntax doesn't work in PL/pgSQL, that assigning a scalar subquery to a variable of the composite type in question _does_ work! But don't take that as a question. I'm going to regard this as "case closed".

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2021-08-10 01:03:42 Re: archive_command / single user mode
Previous Message Christophe Pettus 2021-08-09 23:17:36 archive_command / single user mode