This script lock in the update statement following select for update:

eng=sqlalchemy.create_engine('postgres://x.loc/db')
metadata=sqlalchemy.MetaData()
metadata.bind=eng
tab1 = Table('tab1', metadata, autoload=True)

a_rec =
tab1.select( for_update=True ).where(the_condition).execute().fetchone()
tab1.update().where(new_condition).values(stato = 'DEL').execute()


After select this is pg_lock data:
    relname     | locktype | transaction |  pid  |      mode
----------------+----------+-------------+-------+-----------------
     tab1    | relation |     6788234 | 28293 | AccessShareLock
     tab1    | relation |     6788234 | 28293 | RowShareLock

During update this is pg_lock data:
    relname     | locktype | transaction |  pid  |       mode
----------------+----------+-------------+-------+------------------
     tab1    | tuple    |     6788240 | 28294 | ExclusiveLock
     tab1    | relation |     6788234 | 28293 | AccessShareLock
     tab1    | relation |     6788234 | 28293 | RowShareLock
     tab1    | relation |     6788240 | 28294 | AccessShareLock
     tab1    | relation |     6788240 | 28294 | RowExclusiveLock

Note: the script generate two different transactions.
What is wrong ?
An equivalent "psycopg2 only" script work fine.

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to