Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rO1uB-000bBg-3I for pgsql-docs@arkaria.postgresql.org; Thu, 11 Jan 2024 20:43:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rO1u9-00EoqE-Jq for pgsql-docs@arkaria.postgresql.org; Thu, 11 Jan 2024 20:43:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rO1u9-00Eoq6-CM for pgsql-docs@lists.postgresql.org; Thu, 11 Jan 2024 20:43:57 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rO1u7-0014dd-6T for pgsql-docs@lists.postgresql.org; Thu, 11 Jan 2024 20:43:56 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 40BKhpgJ317972; Thu, 11 Jan 2024 15:43:51 -0500 From: Tom Lane To: "Russell, John" cc: "pgsql-docs@lists.postgresql.org" Subject: Re: Question on doc for RETURNING clause In-reply-to: <9A518B72-829E-4133-B193-0E168D47723E@amazon.com> References: <9A518B72-829E-4133-B193-0E168D47723E@amazon.com> Comments: In-reply-to "Russell, John" message dated "Thu, 11 Jan 2024 18:55:03 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <317970.1705005831.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 11 Jan 2024 15:43:51 -0500 Message-ID: <317971.1705005831@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "Russell, John" 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 =E2=80=9Cthing=E2=80=9D is t= hat 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 a= s 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