Re: BUG #16671: "generated always as" is ignored when updating table through view

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

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Cc: rad@killian.email, pgsql-bugs@lists.postgresql.org
Date: 2020-10-27T23:38:08Z
Lists: pgsql-bugs

Attachments

I wrote:
>> PG Bug reporting form <noreply@postgresql.org> writes:
>>> [ updating via a view fails to recalculate GENERATED columns ]

>> Yeah, that's surely a bug.  In fact, it's a regression, because
>> the test case works as-expected in v12.  Not sure where we broke it.

> git bisect blames
> c6679e4fca21d253ced84c51ac1a31c1b2aec72f is the first bad commit

On digging into this, I see that it's one of the issues I complained
about in [1].  Here is a patch that proposes to fix that by moving
calculation of extraUpdatedCols into the query rewriter.

(With this patch, stored extraUpdatedCols values would always be
null.  But it wouldn't matter if we are working with a rule in which
the field isn't null, since the rewriter would just overwrite it.)

			regards, tom lane

[1] https://www.postgresql.org/message-id/2351.1589824639%40sss.pgh.pa.us

Commits

  1. Calculate extraUpdatedCols in query rewriter, not parser.

  2. Optimize update of tables with generated columns