pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mike Bayer <mike_mp@zzzcomputing.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Guidance on INSERT RETURNING order
Date: Sat, 15 Apr 2023 12:39:55 -0400
Message-ID: <48841e8a-8fbc-46d8-95f3-2b50db23f6a0@app.fastmail.com> (raw)
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>



On Fri, Apr 14, 2023, at 11:17 PM, Tom Lane wrote:
> 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?

in my "plan", the token would not be supported and an error would be raised.   


>
> 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.

I appreciate this idea!    Any kind of keyword / syntax that frees us from having to round-trip additional data to the database and/or generate more complex syntaxes for certain kinds of default generation schemes would simplify the approach.     






view thread (56+ messages)  latest in thread

Message-ID: <48841e8a-8fbc-46d8-95f3-2b50db23f6a0@app.fastmail.com>
Permalink:  ../48841e8a-8fbc-46d8-95f3-2b50db23f6a0@app.fastmail.com/
Also on:    postgresql.org/message-id/48841e8a-8fbc-46d8-95f3-2b50db23f6a0@app.fastmail.com

 · 

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: mike_mp@zzzcomputing.com
  Subject: Re: Guidance on INSERT RETURNING order
  In-Reply-To: <48841e8a-8fbc-46d8-95f3-2b50db23f6a0@app.fastmail.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> <1608813.1681528629@sss.pgh.pa.us> <48841e8a-8fbc-46d8-95f3-2b50db23f6a0@app.fastmail.com>

* 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