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:00:28 -0700
Message-ID: <9b21a499-9352-e1f6-4936-47b024e8b0ef@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,
>
> I have a few clarification questions regarding using insert with returning.
> The use case is SQLAlchemy development, where the orm wants to insert
> a list of rows,
> get back the generated ids, defaults, etc, and match the returned values with
> the original list of orm objects.
>
> The following assumes a table like this
>
> CREATE TABLE t(
> id SERIAL,
> data TEXT -- type here can be anything
> )
>
> On PostgreSQL, since SQLAlchemy version 1.4 (Mar 2021) this operation has used
>
> INSERT INTO t(data) VALUES ('a'), ('b'), ('c') RETURNING id
>
> but we were recently made aware that there is no guarantee on the
> order of the returned columns.
1) Because returned data in SQL is inherently unordered.
2) What would you order by, id or data or both?
> Sorry for the long email,
> Thanks
>
> Federico
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
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: <9b21a499-9352-e1f6-4936-47b024e8b0ef@aklaver.com>
References: <CAN19dycS0oUorLOGgjxMX8NZq-hOA1RJrzwC4L3FxpMf4BQbBQ@mail.gmail.com> <9b21a499-9352-e1f6-4936-47b024e8b0ef@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