On Apr 13, 1:47 pm, "Koen Bok" <[EMAIL PROTECTED]> wrote:
> request_table = Table('request', metadata,
>         Column('id', Integer, primary_key=True),
>         Column('number', Integer, unique=True, nullable=True,
>                 default=text('(SELECT coalesce(max(number), 0) + 1 FROM 
> request)')))
>
> This seems to work well. But is  this a good way to do this or can it
> cause complications?

This will start to throw duplicate key errors under heavier load.
There is a window of time between insert and commit when another
insert will get the same duplicate id. It might not be a problem in
your case, but I have had to deal with a similar problem when creating
sequentally hashed database table (for provable temporal ordering and
integrity) which will see very high loads. You'll either occasionally
get duplicate values in the database or you have to serialize all
inserts. The best that can be done, is try to occasionally get holes
and assume that usually transactions succeed and catch rollbacks. That
is a lot harder.

Ants


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to