pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Vitaly Ustinov <vitaly@ustinov.ca>
Cc: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Cc: pgsql-bugs@lists.postgresql.org, "David G. Johnston" <david.g.johnston@gmail.com>
Subject: Re: Generated column is not updated (Postgres 13)
Date: Thu, 20 May 2021 17:09:08 -0400
Message-ID: <3795805.1621544948@sss.pgh.pa.us> (raw)
In-Reply-To: <CAM_DEiX+P9YvpeYu_Dc6WoW=d2kcLAC2O=pT_Y+e_eYhBTSLPg@mail.gmail.com>
References: <CAM_DEiWR2DPT6U4xb-Ehigozzd3n3G37ZB1+867zbsEVtYoJww@mail.gmail.com>
	<3513055.1621461801@sss.pgh.pa.us>
	<3569485.1621475748@sss.pgh.pa.us>
	<CAM_DEiVP-mi6PVGcsbFOUS39O-4qsFpKprvKJ1u2APrG98T65w@mail.gmail.com>
	<CAM_DEiU77gQr+-85PfjDzY2rQLeQewTkadXGdXHimvqTUFXvoQ@mail.gmail.com>
	<3689916.1621525992@sss.pgh.pa.us>
	<CAM_DEiX+P9YvpeYu_Dc6WoW=d2kcLAC2O=pT_Y+e_eYhBTSLPg@mail.gmail.com>

Vitaly Ustinov <vitaly@ustinov.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





view thread (10+ messages)

Message-ID: <3795805.1621544948@sss.pgh.pa.us>
Permalink:  ../3795805.1621544948@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3795805.1621544948@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, vitaly@ustinov.ca, peter.eisentraut@enterprisedb.com, david.g.johnston@gmail.com
  Subject: Re: Generated column is not updated (Postgres 13)
  In-Reply-To: <3795805.1621544948@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox