pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Russell, John <johrss@amazon.com>
Cc: pgsql-docs@lists.postgresql.org <pgsql-docs@lists.postgresql.org>
Subject: Re: Question on doc for RETURNING clause
Date: Thu, 11 Jan 2024 15:43:51 -0500
Message-ID: <317971.1705005831@sss.pgh.pa.us> (raw)
In-Reply-To: <9A518B72-829E-4133-B193-0E168D47723E@amazon.com>
References: <9A518B72-829E-4133-B193-0E168D47723E@amazon.com>

"Russell, John" <johrss@amazon.com> writes:
> Hi, I was thinking of suggesting some doc clarifications and additional examples related to the RETURNING clause. Just a 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 result set?

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





view thread (4+ messages)  latest in thread

Message-ID: <317971.1705005831@sss.pgh.pa.us>
Permalink:  ../317971.1705005831@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/317971.1705005831@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, johrss@amazon.com, pgsql-docs@lists.postgresql.org
  Subject: Re: Question on doc for RETURNING clause
  In-Reply-To: <317971.1705005831@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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