pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Federico <cfederico87@gmail.com>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: John Howroyd <jdhowroyd@googlemail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Guidance on INSERT RETURNING order
Date: Fri, 14 Apr 2023 23:17:09 -0400
Message-ID: <1608813.1681528629@sss.pgh.pa.us> (raw)
In-Reply-To: <CAN19dye=rfDRL=40QDko=yPggE0rotesr2sg1LSih-1c7v0fZQ@mail.gmail.com>
References: <CAN19dycS0oUorLOGgjxMX8NZq-hOA1RJrzwC4L3FxpMf4BQbBQ@mail.gmail.com>
	<95fbd8c8-2f7a-38a1-4a41-b2ac3763d89c@aklaver.com>
	<CAN19dyed0o5eCUYSEq30q39SpFmeZ7WSEHBfR042YYTVoipHcg@mail.gmail.com>
	<6644419d-50e1-97c9-5507-b6915bec96fa@gmail.com>
	<CAN19dydktTMU8hQ+2-PkaPf6PV6HFOvDwODD0cchNxVuVXSvKg@mail.gmail.com>
	<961adda9-4eb1-79f6-ee8f-9440a520ac15@gmail.com>
	<20230414164036.labzn5sbqzye7jvg@hjp.at>
	<CAAGaYBz3D6DWRmE_vaLxGBdCpTODw8GrKj=u=Ex3py0fwjf5vw@mail.gmail.com>
	<CAKFQuwa0f58-GHOko8bjSQePtq-H-yL4afL2+m687KoE5Mex_Q@mail.gmail.com>
	<CAN19dye=rfDRL=40QDko=yPggE0rotesr2sg1LSih-1c7v0fZQ@mail.gmail.com>

Federico <cfederico87@gmail.com> writes:
> Would something like what was proposed by Mike Bayer be considered?

>> A new token called "tuple_order" or something
>> 
>> INSERT INTO table (a, b, c) VALUES ((1, 2, 3), (4, 5, 6), ...) RETURNING table.id, inserted.tuple_order
>> 
>> tuple_order would be incrementing values 1, 2, 3, 4, 5, ... which correlate the each row delivered by RETURNING to each entry in the VALUES clause, in the order they were stated in that VALUES clause, that is entry (1, 2, 3) would be tuple_order 1, entry (4, 5, 6) would be tuple order 2, etc.

As proposed, I don't think so.  Something over in the RETURNING clause has
exactly no connection to VALUES.  What do you do if it's INSERT ... SELECT
and there are several VALUES clauses down inside the SELECT?

There is some prior art in this area, though.  See the more-or-less
SQL-standard WITH ORDINALITY option for functions-in-FROM.  It seems to me
that it could be plausible to attach WITH ORDINALITY to a VALUES clause,
which would give you a rock-solid connection between the VALUES rows and
the ordinality-column values, and then you could include that column in
RETURNING.

			regards, tom lane





view thread (56+ messages)  latest in thread

Message-ID: <1608813.1681528629@sss.pgh.pa.us>
Permalink:  ../1608813.1681528629@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1608813.1681528629@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, cfederico87@gmail.com, david.g.johnston@gmail.com, jdhowroyd@googlemail.com
  Subject: Re: Guidance on INSERT RETURNING order
  In-Reply-To: <1608813.1681528629@sss.pgh.pa.us>
  References: <CAN19dycS0oUorLOGgjxMX8NZq-hOA1RJrzwC4L3FxpMf4BQbBQ@mail.gmail.com> <95fbd8c8-2f7a-38a1-4a41-b2ac3763d89c@aklaver.com> <CAN19dyed0o5eCUYSEq30q39SpFmeZ7WSEHBfR042YYTVoipHcg@mail.gmail.com> <6644419d-50e1-97c9-5507-b6915bec96fa@gmail.com> <CAN19dydktTMU8hQ+2-PkaPf6PV6HFOvDwODD0cchNxVuVXSvKg@mail.gmail.com> <961adda9-4eb1-79f6-ee8f-9440a520ac15@gmail.com> <20230414164036.labzn5sbqzye7jvg@hjp.at> <CAAGaYBz3D6DWRmE_vaLxGBdCpTODw8GrKj=u=Ex3py0fwjf5vw@mail.gmail.com> <CAKFQuwa0f58-GHOko8bjSQePtq-H-yL4afL2+m687KoE5Mex_Q@mail.gmail.com> <CAN19dye=rfDRL=40QDko=yPggE0rotesr2sg1LSih-1c7v0fZQ@mail.gmail.com> <1608813.1681528629@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