Re: Question on doc for RETURNING clause - Mailing list pgsql-docs

From Tom Lane
Subject Re: Question on doc for RETURNING clause
Date
Msg-id 317971.1705005831@sss.pgh.pa.us
Whole thread Raw
In response to Question on doc for RETURNING clause  ("Russell, John" <johrss@amazon.com>)
Responses Re: Question on doc for RETURNING clause
List pgsql-docs
"Russell, John" <johrss@amazon.com> writes:
> Hi, I was thinking of suggesting some doc clarifications and additional examples related to the RETURNING clause.
Justa couple of questions first to see if my understanding is correct. 

> I was trying to figure out what the precise “thing” is that comes back from a RETURNING clause. A table reference? A
resultset? 

I'd say it's a result set, just like the output of SELECT.

> That made me think both a RETURNING clause could work in contexts such as CTE (yes) and subquery (seems like no).

We disallow DML in subqueries because there's a lot of squishiness
around when a subquery is evaluated, whether it's evaluated to
completion, or indeed whether it's evaluated more than once.
CTEs have tighter semantics and so it's practical to require
"exactly once" evaluation for CTEs.  Partly this is a matter of
historical expectations, but I doubt we'd consider revisiting it.

>> PostgreSQL allows INSERT, UPDATE, and DELETE to be used as WITH queries. This is not found in the SQL standard.

> Is MERGE allowed in that ^^^ context?

Not yet, as you'd find out if you tried it.  I think there's a patch
in the pipeline to allow it.

            regards, tom lane



pgsql-docs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: Question on doc for RETURNING clause
Next
From: "Russell, John"
Date:
Subject: Re: Question on doc for RETURNING clause