From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
---|---|
To: | Federico <cfederico87(at)gmail(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org |
Cc: | Mike Bayer <mike_mp(at)zzzcomputing(dot)com> |
Subject: | Re: Guidance on INSERT RETURNING order |
Date: | 2023-04-11 20:00:28 |
Message-ID: | 9b21a499-9352-e1f6-4936-47b024e8b0ef@aklaver.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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(dot)klaver(at)aklaver(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Adrian Klaver | 2023-04-11 20:06:45 | Re: Guidance on INSERT RETURNING order |
Previous Message | Federico | 2023-04-11 19:47:08 | Guidance on INSERT RETURNING order |