9 messages in com.googlegroups.sqlalchemy[sqlalchemy] sequence-related question
FromSent OnAttachments
Eric Lemoine30 Apr 2008 09:56 
Michael Bayer30 Apr 2008 12:02 
Eric Lemoine30 Apr 2008 12:22 
Eric Lemoine30 Apr 2008 12:25 
Michael Bayer30 Apr 2008 12:44 
Eric Lemoine30 Apr 2008 12:45 
Eric Lemoine30 Apr 2008 13:08 
Michael Bayer30 Apr 2008 13:08 
Eric Lemoine02 May 2008 09:17 
Subject:[sqlalchemy] sequence-related question
From:Eric Lemoine (eric@gmail.com)
Date:04/30/2008 09:56:06 AM
List:com.googlegroups.sqlalchemy

Hello

I insert a new line in a table using this:

campfacility = Campfacility(prop1, prop2) model.Session.save(campfacility) model.Session.commit()

The campfacility id is handled by a postgres sequence.

What I'd like to do is:

campfacility = Campfacility(prop1, prop2) seq = Sequence('some_sequence') model.Session.execute(seq) model.Session.save(campfacility) model.Session.commit()

to know before inserting the line what id it will get. The above code doesn't seem thread-safe to me:

thread 1 thread 2 execute(seq) -> nextid = n

execute(seq) -> nextid = n model.Session.save(campfacility)

model.Session.save(campfacility) -> BUG, nextid isn't correct

I'm sure there's a way to make this thread-safe but right now I just don't know how.

Can someone help?

Thanks a lot,

PS: I just love SA ;-)