Re: Generated column is not updated (Postgres 13) - Mailing list pgsql-bugs

From David G. Johnston
Subject Re: Generated column is not updated (Postgres 13)
Date
Msg-id CAKFQuwZaFiiGphgJsJgV0tUkaA_Z2zQXodvWkx9enR7hjHRmKQ@mail.gmail.com
Whole thread Raw
In response to Re: Generated column is not updated (Postgres 13)  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Generated column is not updated (Postgres 13)  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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.

pgsql-bugs by date:

Previous
From: Michael Paquier
Date:
Subject: Re: BUG #17023: wal_log_hints not configured even if it on
Next
From: David Rowley
Date:
Subject: Re: Less selective index chosen unexpectedly