Re: Unexpected behavior when combining `generated always` columns and update rules

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Ciprian Craciun <ciprian(dot)craciun(at)gmail(dot)com>
Cc: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Unexpected behavior when combining `generated always` columns and update rules
Date: 2023-04-13 14:32:08
Message-ID: CAKFQuwakXc0RRNU49n1FYmXXDBukvTeDRbXZZ+Fuyy2y-Z5N=g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thursday, April 13, 2023, Ciprian Craciun <ciprian(dot)craciun(at)gmail(dot)com>
wrote:

>
> create or replace rule propagate_x_and_d as on update to x do also
> update y set x = new.x, d = new.d where y.x = old.x;
>
> As seen above, although the rule correctly propagates the change to
> the `x` column, it fails to use the new value for the `d` column, but
> instead uses the previous one.
>

ALSO rules behave like before triggers, not after triggers. The original
command is appended to the end of the list of commands, not the start.

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2023-04-13 14:37:40 Re: Unexpected behavior when combining `generated always` columns and update rules
Previous Message Ciprian Craciun 2023-04-13 14:02:17 Unexpected behavior when combining `generated always` columns and update rules