Hi folks, I'm working on a legacy database that has some issues with PK generation. The long and short of it is that for now, I need to generate an PK by locking a table, because that's what they've been doing. I'm using the orm, and basically want to be able to use a session briefly with the table locked. ( to find the highest PK in there and increment. I know....hope we can fix that later ). I'm wondering what the best way to do this is.
I could use a connection to lock the table with raw sql, but then can I use a session for the query? I think what I want in magical pseudo code is this, comments appreciated (aside from the fact that this is not a good way to get a pk, no choice there) # lock the table somehow? session.LOCKER( table to lock) last_pk = session.query(Client).order_by( desc(Client.pk) ).limit(1).get().pk # insert new client session.add( Client(pk= last_pk+1, **other_values) ) session.commit() # unlock table session.UNLOCKER thanks Iain -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.