Re: Getting sequence-generated IDs from multiple row insert - Mailing list pgsql-general

From David Johnston
Subject Re: Getting sequence-generated IDs from multiple row insert
Date
Msg-id 1396298044794-5798107.post@n5.nabble.com
Whole thread Raw
In response to Re: Getting sequence-generated IDs from multiple row insert  (Andrew Sullivan <ajs@crankycanuck.ca>)
Responses Re: Getting sequence-generated IDs from multiple row insert  (Andrew Sullivan <ajs@crankycanuck.ca>)
List 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.


pgsql-general by date:

Previous
From: Si Chen
Date:
Subject: Re: getting the current query from pg_stat_activity
Next
From: Edson Richter
Date:
Subject: Re: Why does "checkpointer" is consumig ~1.2Gb of RAM?