Re: plpgsql variable assignment with union is broken

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: easteregg@verfriemelt.org
Cc: pgsql-hackers@lists.postgresql.org
Date: 2021-01-05T21:40:46Z
Lists: pgsql-hackers
easteregg@verfriemelt.org writes:
> i found, that the behaviour of variable assignment in combination with union is not working anymore:
>   DO $$ 
>   DECLARE t bool; 
>   begin 
>       t := a FROM ( SELECT true WHERE false ) t(a) UNION SELECT true AS a; 
>   END $$;

> is this an intended change or is it a bug?

It's an intended change, or at least I considered the case and thought
that it was useless because assignment will reject any result with more
than one row.  Do you have any non-toy example that wouldn't be as
clear or clearer without using UNION?  The above sure seems like an
example of awful SQL code.

			regards, tom lane