pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Ciprian Craciun <ciprian.craciun@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Unexpected behavior when combining `generated always` columns and update rules
Date: Thu, 13 Apr 2023 10:03:25 -0700
Message-ID: <610e53b5-aba2-d232-9448-765327b88431@aklaver.com> (raw)
In-Reply-To: <CA+Tk8fyW4d2Q6yKq1dOH3o5LEt2VQ-QPgfrP1tdq0sUC8nVj8Q@mail.gmail.com>
References: <CA+Tk8fz+Vuov584ff_PxxptB=dG3tX_buFr+4RTvFCN5ERFN4Q@mail.gmail.com>
	<CAKFQuwakXc0RRNU49n1FYmXXDBukvTeDRbXZZ+Fuyy2y-Z5N=g@mail.gmail.com>
	<CA+Tk8fyW4d2Q6yKq1dOH3o5LEt2VQ-QPgfrP1tdq0sUC8nVj8Q@mail.gmail.com>

On 4/13/23 09:27, Ciprian Craciun wrote:
> On Thu, Apr 13, 2023 at 5:32 PM David G. Johnston
> <david.g.johnston@gmail.com> wrote:
>> 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.
> 
> 
> As Tom observed, the documentation states that in case of update
> rules, the original query is executed at the end.
> 
> However, regardless of the order of the execution between new and
> original query, as per the documentation the `new` table should
> contain the new values regardless.
> 
> In fact, from my example above, one can see that the `y.x` is properly
> updated with the new value, meanwhile the `y.d` is the previous one
> (i.e. `old.d`).
> 
> So, based on these observations, I think that `generated always`
> columns are actually computed on insertion, and thus they are not
> reflected in `new` on rules.

Just realized we may have both being saying the same thing. That your 
'...actually computed on insertion,...' meant not just for an INSERT but 
for any change in the data. In other words when the original query 
actually ran.

> 
> Ciprian.
> 
> 

-- 
Adrian Klaver
adrian.klaver@aklaver.com






view thread (7+ messages)  latest in thread

Message-ID: <610e53b5-aba2-d232-9448-765327b88431@aklaver.com>
Permalink:  ../610e53b5-aba2-d232-9448-765327b88431@aklaver.com/
Also on:    postgresql.org/message-id/610e53b5-aba2-d232-9448-765327b88431@aklaver.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, ciprian.craciun@gmail.com, tgl@sss.pgh.pa.us, david.g.johnston@gmail.com
  Subject: Re: Unexpected behavior when combining `generated always` columns and update rules
  In-Reply-To: <610e53b5-aba2-d232-9448-765327b88431@aklaver.com>
  References: <CA+Tk8fz+Vuov584ff_PxxptB=dG3tX_buFr+4RTvFCN5ERFN4Q@mail.gmail.com> <CAKFQuwakXc0RRNU49n1FYmXXDBukvTeDRbXZZ+Fuyy2y-Z5N=g@mail.gmail.com> <CA+Tk8fyW4d2Q6yKq1dOH3o5LEt2VQ-QPgfrP1tdq0sUC8nVj8Q@mail.gmail.com> <610e53b5-aba2-d232-9448-765327b88431@aklaver.com>

* 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