Re: Guidance on INSERT RETURNING order

From: Thorsten Glaser <tg(at)evolvis(dot)org>
To: Kirk Wolak <wolakk(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Guidance on INSERT RETURNING order
Date: 2023-04-12 22:24:13
Message-ID: c422c4ef-a284-e45e-b968-27bff221e993@evolvis.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 12 Apr 2023, Kirk Wolak wrote:

>The solution exists. Pre-fetch the IDs, assign them and insert them with
>the IDs. Then you have 100% control.
>SELECT NEXTVAL('tbl_seq') from GENERATE_SERIES(1, <total_needed>);

This would be a nice solution… but the PK could be always generated,
or not even sequential (UUIDs for example). If you’re developing
schema-first the application would not even (need to) know about how
the IDs are generated as it’s the DB that generates them.

AIUI the OP’s an SQLAlchemy developer, which is an ORM. Therefore he
needs a generic solution.

bye,
//mirabilos
--
15:41⎜<Lo-lan-do:#fusionforge> Somebody write a testsuite for helloworld :-)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rob Sargent 2023-04-12 22:29:54 Re: Guidance on INSERT RETURNING order
Previous Message Kirk Wolak 2023-04-12 22:13:19 Re: Guidance on INSERT RETURNING order