Re: Joins of data-modifying CTE with the target table

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alex Bolenok <quassnoi(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Joins of data-modifying CTE with the target table
Date: 2023-04-19 16:53:14
Message-ID: 2991189.1681923194@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alex Bolenok <quassnoi(at)gmail(dot)com> writes:
> To answer your question, by "explicitly" I mean mentioning this very
> pattern, where you join the returned id with the target table.

I do not see why this existing example isn't sufficient:

... An example of this is that in

WITH t AS (
UPDATE products SET price = price * 1.05
RETURNING *
)
SELECT * FROM products;

the outer SELECT would return the original prices before the action of
the UPDATE, ...

Yeah, it lacks a JOIN and it's an UPDATE not an INSERT. But we can't
provide an example to precisely match every possible mistake. As
Adrian said, brevity in the docs does have value.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message gzh 2023-04-19 17:02:43 Re: psql:t_mstr.sql:994: ERROR: function to_char(numeric) does not exist
Previous Message Adrian Klaver 2023-04-19 16:42:45 Re: Joins of data-modifying CTE with the target table