Re: Generated column is not updated (Postgres 13)
David G. Johnston <david.g.johnston@gmail.com>
From: "David G. Johnston" <david.g.johnston@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Vitaly Ustinov <vitaly@ustinov.ca>, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>, Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Date: 2021-05-20T01:02:39Z
Lists: pgsql-bugs
On Wed, May 19, 2021 at 3:03 PM Tom Lane <tgl@sss.pgh.pa.us> wrote: > Vitaly Ustinov <vitaly@ustinov.ca> writes: > > I would like to report the following: > > - a generated column is never updated if you pass the whole record to a > > stored procedure (an immutable function); > > You could perhaps argue that it'd be okay to pass NULL. The problem > with that, though, is that it'd violate the NOT NULL constraint that > exists for the generated column. Quite aside from any confusion that > ensues at the user level, I'm afraid that that could result in C code > crashes --- there are, for example, places in tuple deforming that > assume that NOT NULL constraints are truthful. > Knowing why version 12 worked would be helpful in judging whether to live with past decisions, fix poorly made previous decisions, or just move forward with the new behavior in v14 and leave the past alone. I agree that the better design choice would have us forbid this, though that seems problematic in its own right. The function itself is defined correctly and aside from the fact it is in a generated expression it is also called correctly. I suppose the error would be of the form "cannot form a valid whole-row var due to unspecified generated column data"? FWIW I can definitely see where the OP is coming from with this - the expression at first blush, if one assumes PostgreSQL can handle the nuances, seems like a perfectly reasonable semantic way to express the programmer's desire. Combined with the fact it used to work makes me want to lean toward keeping it working even if it takes come code hackery. David J.
Commits
-
Disallow whole-row variables in GENERATED expressions.
- 61feb8670824 12.8 landed
- 849c7971d1ab 13.4 landed
- 4b10074453d1 14.0 landed
-
Fix usage of "tableoid" in GENERATED expressions.
- dfe51ffbe78a 12.8 landed
- 77e3204ecbf1 13.4 landed
- 2b0ee126bbf0 14.0 landed