Re: Generated column is not updated (Postgres 13)

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

Vitaly Ustinov <vitaly(at)ustinov(dot)ca> writes:
> In a BEFORE trigger (PL/pgSQL) I can access not yet computed generated
> columns via the "NEW" whole-row var. I can read from it (NULL), and I
> can write to it, but the assigned value will be ignored.

NEW is not really a whole-row var in the sense that we're discussing
here. In any case, yes, nodeModifyTable runs computation of generated
columns after firing BEFORE triggers. I suppose that's to prevent
the triggers from interfering with those values.

> Is it okay with you that the patch 0002 introduces some inconsistency with that?

In what way would this introduce (new) inconsistency? I didn't move
the computation of those values from where they were. Moreover, so
far as I can see, ATRewriteTable doesn't fire BEFORE triggers at all.

BTW, while looking around nodeModifyTable, I noted some other gaps in our
support for "tableoid" in GENERATED expressions: the FDW code paths in
ExecInsert and ExecUpdate fail to fill tts_tableOid till after running
ExecComputeStoredGenerated. So they have the same bug that 0001 fixes
in ATRewriteTable. It can be fixed the same way, ie move the code
that fills tts_tableOid; but I remain very concerned about how many
other gaps there are.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message David Christensen 2021-05-20 21:57:22 ResultCache cache error: "cache entry already complete" in 14beta1
Previous Message Vitaly Ustinov 2021-05-20 19:07:34 Re: Generated column is not updated (Postgres 13)