Re: Getting sequence-generated IDs from multiple row insert

From: David Johnston <polobo(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Getting sequence-generated IDs from multiple row insert
Date: 2014-03-31 20:34:04
Message-ID: 1396298044794-5798107.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Andrew Sullivan-8 wrote
>> So currently I've changed my code to use RETURNING and then I'm ordering
>> the results based on a secondary column that I know the order of. This
>> works, but seems clunky, so I'm wondering if there's a nicer way.
>
> This is probably what I'd do, assuming that "further processing" isn't
> more data transformation. If it _is_, then I'd do the whole thing in
> a single step (in the database, once I inserted).

If order is an implicit property of the source data then you need to
explicitly encode that order during (or before) import. There are numerous
ways to implement such but except for extremely simple cases PostgreSQL will
not do the appropriate thing automatically in the face of concurrency.

Also, do you need sequential IDs or just IDs that are ever increasing? And
if the later then tagging the input source will let you distinguish between
two different datasets even if their sequences are overlapping.

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Getting-sequence-generated-IDs-from-multiple-row-insert-tp5798092p5798107.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Edson Richter 2014-03-31 20:46:42 Re: Why does "checkpointer" is consumig ~1.2Gb of RAM?
Previous Message Si Chen 2014-03-31 20:33:12 Re: getting the current query from pg_stat_activity