Re: Guidance on INSERT RETURNING order - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Guidance on INSERT RETURNING order
Date
Msg-id 9b21a499-9352-e1f6-4936-47b024e8b0ef@aklaver.com
Whole thread Raw
In response to Guidance on INSERT RETURNING order  (Federico <cfederico87@gmail.com>)
List 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.klaver@aklaver.com




pgsql-general by date:

Previous
From: Federico
Date:
Subject: Guidance on INSERT RETURNING order
Next
From: Adrian Klaver
Date:
Subject: Re: Guidance on INSERT RETURNING order