Re: Bug: Rule actions see wrong values for generated columns (NEW.gen reads OLD value)

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Richard Guo <guofenglinux(at)gmail(dot)com>
Cc: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, SATYANARAYANA NARLAPURAM <satyanarlapuram(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Peter Eisentraut <peter(at)eisentraut(dot)org>
Subject: Re: Bug: Rule actions see wrong values for generated columns (NEW.gen reads OLD value)
Date: 2026-04-20 08:42:31
Message-ID: CAEZATCURLESGChXr5ZweoGCGQ9dadM4Hs2eSUjBmXV3OguN4WQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, 20 Apr 2026 at 08:29, Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
>
> I noticed a couple of issues after a further look.
>
> 1. The ReplaceVarsFromTargetList call on "gen_cols" fails to handle
> hasSubLinks. This can cause error if targetList contains SubLinks:
>
> update t set a = (select max(a) from t);
> ERROR: replace_rte_variables inserted a SubLink, but has noplace to record it
>

Doh, yes, careless copy-and-pasting. The updates look good.

> 2. The same bug fixed in this patch also exists in rule quals:
>
> I think we should apply the same fix to CopyAndAddInvertedQual.
>

Agreed.

> Attached v3 fixes them.
>

LGTM.

Regards,
Dean

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Yuchen Li 2026-04-20 08:49:35 Re: EXCEPT TABLE - Case inconsistency for describe \d and \dRp+
Previous Message Daniel Gustafsson 2026-04-20 08:26:22 Re: [PATCH] Reject ENCODING option for COPY TO FORMAT JSON