[GENERAL] Getting sequence-generated IDs from multiple row insert

2014-03-31 Thread Ben Hoyt
Hi folks, I've just run into a subtle but fairly serious race condition while using web.py's SQL library to insert multiple rows into the database and return their IDs (a serial primary key column). Specifically I'm using the multiple_insert() function that web.py defines here:

Re: [GENERAL] Getting sequence-generated IDs from multiple row insert

2014-03-31 Thread Andrew Sullivan
On Mon, Mar 31, 2014 at 03:28:14PM -0400, Ben Hoyt wrote: , but I've just hit a case where two sessions each doing a multiple insert don't use sequential IDs. For example, the range code above for the first insert gave 2117552...2117829. And the second insert gave 2117625...2117818. Which are

Re: [GENERAL] Getting sequence-generated IDs from multiple row insert

2014-03-31 Thread David Johnston
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

Re: [GENERAL] Getting sequence-generated IDs from multiple row insert

2014-03-31 Thread Andrew Sullivan
On Mon, Mar 31, 2014 at 01:34:04PM -0700, David Johnston wrote: If order is an implicit property of the source data then you need to explicitly encode that order during (or before) import. Sure, but the problem the OP had I thought was that the RETURNING clause doesn't guarantee that the