agora inbox for pgsql-docs@postgresql.org
help / color / mirror / Atom feedData visibility for returning statement
2+ messages / 2 participants
[nested] [flat]
* Data visibility for returning statement
@ 2025-04-25 07:21 PG Doc comments form <noreply@postgresql.org>
2025-07-14 01:30 ` Re: Data visibility for returning statement David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: PG Doc comments form @ 2025-04-25 07:21 UTC (permalink / raw)
To: pgsql-docs@lists.postgresql.org; +Cc: robin@jonssonhector.com
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?
Best regards
Robin
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Data visibility for returning statement
2025-04-25 07:21 Data visibility for returning statement PG Doc comments form <noreply@postgresql.org>
@ 2025-07-14 01:30 ` David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 0 replies; 2+ messages in thread
From: David G. Johnston @ 2025-07-14 01:30 UTC (permalink / raw)
To: robin@jonssonhector.com; pgsql-docs@lists.postgresql.org
On Sat, Apr 26, 2025 at 5:50 AM PG Doc comments form <noreply@postgresql.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.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2025-07-14 01:30 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-04-25 07:21 Data visibility for returning statement PG Doc comments form <noreply@postgresql.org>
2025-07-14 01:30 ` David G. Johnston <david.g.johnston@gmail.com>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox