pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Federico <cfederico87@gmail.com>
To: pgsql-general@lists.postgresql.org
Cc: Mike Bayer <mike_mp@zzzcomputing.com>
Subject: Re: Guidance on INSERT RETURNING order
Date: Tue, 11 Apr 2023 13:06:45 -0700
Message-ID: <95fbd8c8-2f7a-38a1-4a41-b2ac3763d89c@aklaver.com> (raw)
In-Reply-To: <CAN19dycS0oUorLOGgjxMX8NZq-hOA1RJrzwC4L3FxpMf4BQbBQ@mail.gmail.com>
References: <CAN19dycS0oUorLOGgjxMX8NZq-hOA1RJrzwC4L3FxpMf4BQbBQ@mail.gmail.com>

On 4/11/23 12:47, Federico wrote:
> Hello list,
> 
https://www.sqlite.org/lang_returning.html#limitations_and_caveats
> 
> Searching the archive seems that a using the INSERT SELECT ORDER BY
> form should be a better solution,
> so the above insert should be rewritten as
> 
>      INSERT INTO t(data)
>      SELECT data FROM (VALUES ('a', 1), ('b', 2), ('c', 3)) as vv(data,
> num) ORDER BY num
>      RETURNING id

Or

with i as (INSERT INTO t(data) VALUES ('a', 1), ('b', 2), ('c', 3) 
returning id)
select i.id from i order by id;

> Sorry for the long email,
> Thanks
> 
>      Federico
> 
> 

-- 
Adrian Klaver
adrian.klaver@aklaver.com






view thread (56+ messages)  latest in thread

Message-ID: <95fbd8c8-2f7a-38a1-4a41-b2ac3763d89c@aklaver.com>
Permalink:  ../95fbd8c8-2f7a-38a1-4a41-b2ac3763d89c@aklaver.com/
Also on:    postgresql.org/message-id/95fbd8c8-2f7a-38a1-4a41-b2ac3763d89c@aklaver.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: adrian.klaver@aklaver.com, cfederico87@gmail.com, mike_mp@zzzcomputing.com
  Subject: Re: Guidance on INSERT RETURNING order
  In-Reply-To: <95fbd8c8-2f7a-38a1-4a41-b2ac3763d89c@aklaver.com>
  References: <CAN19dycS0oUorLOGgjxMX8NZq-hOA1RJrzwC4L3FxpMf4BQbBQ@mail.gmail.com> <95fbd8c8-2f7a-38a1-4a41-b2ac3763d89c@aklaver.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