Re: Generated column is not updated (Postgres 13)

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Vitaly Ustinov <vitaly(at)ustinov(dot)ca>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>, Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
Subject: Re: Generated column is not updated (Postgres 13)
Date: 2021-05-20 01:02:39
Message-ID: CAKFQuwZaFiiGphgJsJgV0tUkaA_Z2zQXodvWkx9enR7hjHRmKQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, May 19, 2021 at 3:03 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Vitaly Ustinov <vitaly(at)ustinov(dot)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.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David Rowley 2021-05-20 01:06:31 Re: Less selective index chosen unexpectedly
Previous Message Michael Paquier 2021-05-20 00:15:48 Re: BUG #17023: wal_log_hints not configured even if it on