On Jun 6, 2010, at 5:18 PM, marco vaccari wrote:
> 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()
above, you're using connectionless execution. This feature is documented here:
http://www.sqlalchemy.org/docs/dbengine.html#connectionless-execution-implicit-execution
. The transactional behavior is described there and is basically not what you
want here.
>
>
> 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 [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.
>
--
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.