From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | robin(at)jonssonhector(dot)com, pgsql-docs(at)lists(dot)postgresql(dot)org |
Subject: | Re: Data visibility for returning statement |
Date: | 2025-07-14 01:30:59 |
Message-ID: | CAKFQuwZva2EhVxeyVEtYyDs9RoOzf3XWzNUEpJ==FBSifSHoAw@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-docs |
On Sat, Apr 26, 2025 at 5:50 AM PG Doc comments form <noreply(at)postgresql(dot)org>
wrote:
> The following documentation comment has been logged on the website:
>
> Page: https://www.postgresql.org/docs/17/dml-returning.html
> Description:
>
> Today I found a pretty special use-case for the "RETURNING" functionality,
> which I cannot find documentation for?
> If you have a statement as follows:
> UPDATE persons SET name = 'Bob' WHERE id = 4
> RETURNING (SELECT name FROM persons WHERE id = 4)
> The returning data will be whatever the value was before the row was
> modified. This differs from if I were to "RETURNING name". I found this to
> be interesting and could possibly warrant some kind of explanation in the
> documentation?
>
>
I would not want to encourage that form of query. The novelty is more
problematic than the brevity. Plus, repetition.
with new_p as ( update persons set name = 'Bob' returning name where id = 4)
select
old_p.id as id,
old_p.name as old_name,
new_p.name as new_name
from persons as old_p
join new_p on new_p.id = old_p.id
And now that we actually allow references to "new" and "old" in v18 that
form is also obsolete and you can do this directly.
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Laurenz Albe | 2025-07-14 06:24:53 | Re: please define 'statement' in the glossary |
Previous Message | David G. Johnston | 2025-07-14 00:32:35 | Re: please define 'statement' in the glossary |