Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ljpuu-0007WK-Ja for pgsql-bugs@arkaria.postgresql.org; Thu, 20 May 2021 21:09:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ljput-0003g8-Ag for pgsql-bugs@arkaria.postgresql.org; Thu, 20 May 2021 21:09:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ljput-0003g0-44 for pgsql-bugs@lists.postgresql.org; Thu, 20 May 2021 21:09:15 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ljpuq-0001sQ-S3 for pgsql-bugs@lists.postgresql.org; Thu, 20 May 2021 21:09:14 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 14KL98F83795806; Thu, 20 May 2021 17:09:08 -0400 From: Tom Lane To: Vitaly Ustinov cc: Peter Eisentraut , pgsql-bugs@lists.postgresql.org, "David G. Johnston" Subject: Re: Generated column is not updated (Postgres 13) In-reply-to: References: <3513055.1621461801@sss.pgh.pa.us> <3569485.1621475748@sss.pgh.pa.us> <3689916.1621525992@sss.pgh.pa.us> Comments: In-reply-to Vitaly Ustinov message dated "Thu, 20 May 2021 15:07:34 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3795804.1621544948.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 20 May 2021 17:09:08 -0400 Message-ID: <3795805.1621544948@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Vitaly Ustinov 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 wi= th 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