pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
https://www.postgresql.org/docs/current/sql-insert.html
2+ messages / 2 participants
[nested] [flat]

* https://www.postgresql.org/docs/current/sql-insert.html
@ 2024-11-02 09:41 PG Doc comments form <noreply@postgresql.org>
  2024-11-05 13:26 ` Re: https://www.postgresql.org/docs/current/sql-insert.html David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Doc comments form @ 2024-11-02 09:41 UTC (permalink / raw)
  To: pgsql-docs@lists.postgresql.org; +Cc: lacroix.robert@outlook.com

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/17/sql-insert.html
Description:

Hi,
the example found in the doc above:

WITH upd AS (
  UPDATE employees SET sales_count = sales_count + 1 WHERE id =
    (SELECT sales_person FROM accounts WHERE name = 'Acme Corporation')
    RETURNING *
)
INSERT INTO employees_log SELECT *, current_timestamp FROM upd;

might result into UPDATE 0 / INSERT 0 because the documentation regarding
the CTE states: "The sub-statements in WITH are executed concurrently with
each other and with the main query".
The subquery SELECT sales_person FROM accounts WHERE name = 'Acme
Corporation' might not be waited on by the UPDATE query resulting into an
UPDATE 0.
Is my suspicion valid?


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: https://www.postgresql.org/docs/current/sql-insert.html
  2024-11-02 09:41 https://www.postgresql.org/docs/current/sql-insert.html PG Doc comments form <noreply@postgresql.org>
@ 2024-11-05 13:26 ` David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: David G. Johnston @ 2024-11-05 13:26 UTC (permalink / raw)
  To: lacroix.robert@outlook.com <lacroix.robert@outlook.com>; pgsql-docs@lists.postgresql.org <pgsql-docs@lists.postgresql.org>

On Saturday, November 2, 2024, 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/sql-insert.html
> Description:
>
> Is my suspicion valid?
>

The presence of the returning clause and subsequent usage of the CTE name
in the select/insert ensures that the update executes first.

David J.

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2024-11-05 13:26 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-11-02 09:41 https://www.postgresql.org/docs/current/sql-insert.html PG Doc comments form <noreply@postgresql.org>
2024-11-05 13:26 ` David G. Johnston <david.g.johnston@gmail.com>

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