Mention RETURNING ... INTO target

Started by PG Bug reporting formalmost 4 years ago4 messagesdocs
Jump to latest
#1PG Bug reporting form
noreply@postgresql.org

The following documentation comment has been logged on the website:

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

It looks like INSERT INTO ... RETURNING allows defining a target for the
returned values like SELECT ... INTO does.

This could be mentioned in the synopsis, or at least in the description of
"output_expression", maybe even garnished with an example.

Thanks,
s.

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: PG Bug reporting form (#1)
Re: Mention RETURNING ... INTO target

n Tue, Jun 7, 2022 at 1:30 PM PG Doc comments form <noreply@postgresql.org>
wrote:

The following documentation comment has been logged on the website:

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

It looks like INSERT INTO ... RETURNING allows defining a target for the
returned values like SELECT ... INTO does.

This could be mentioned in the synopsis, or at least in the description of
"output_expression", maybe even garnished with an example.

That isn't how it works. RETURNING simply turns INSERT into a result set
producing SQL Command. And SQL doesn't have a concept of "target"
(variables) in the sense you are thinking. pg/pgsql does, allowing result
set data to be placed into variables.

If you look you'll notice a corresponding lack of "INTO" on the SELECT
Command reference page as well, for the same reason.

David J.

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: David G. Johnston (#2)
Re: Mention RETURNING ... INTO target

"David G. Johnston" <david.g.johnston@gmail.com> writes:

On Tue, Jun 7, 2022 at 1:30 PM PG Doc comments form <noreply@postgresql.org>
wrote:

It looks like INSERT INTO ... RETURNING allows defining a target for the
returned values like SELECT ... INTO does.

That isn't how it works. RETURNING simply turns INSERT into a result set
producing SQL Command. And SQL doesn't have a concept of "target"
(variables) in the sense you are thinking. pg/pgsql does, allowing result
set data to be placed into variables.

Right. And in fact this *is* documented in the context of pl/pgsql:

https://www.postgresql.org/docs/current/plpgsql-statements.html#PLPGSQL-STATEMENTS-SQL-ONEROW

regards, tom lane

In reply to: Tom Lane (#3)
Re[2]: Mention RETURNING ... INTO target