On Apr 30, 2008, at 12:56 PM, Eric Lemoine wrote:
>
> 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
whats "correct" here, you'd like the integer identifier to be in exact
row-insert order ? if the column is a non-primary key column, the
sequence will be executed "inline" within the executed SQL so that it
will in fact be in row insert order (i.e. update table set
foo_id=nextval(myseq)). you can also do this at flush time by
assigning "func.nextval(literal_column("my_sequence_name"))" to the
mapped attribute (assuming its not a PK).
for primary keys we need to know the ID beforehand in most cases since
PG historically has not had a way to get that ID back nicely after
insert (it has INSERT RETURNING now but we haven't standardized on
that yet).
So if its a PK, I would question why you actually need an incrementing
id in row-insert order on the table in the first place. Usually, if I
want to load records in the order in which they were inserted in a
foolproof way, I'll use a UTC timestamp column with an index for
that....since the information you are looking for here is "what was
inserted when?"
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---