NUM_TERMS = 10
conn = engine.connect()
get_terms = select([search_terms.c.term_id, search_terms.c.term],
and_(search_terms.c.lock==False,
search_terms.c.status==False),
order_by=search_terms.c.term,
limit=NUM_TERMS, for_update="read")
trans = conn.begin()
try:
search_terms = conn.execute(get_terms).fetchall()
for term in search_terms:
lock_terms = update(search_terms).\
where(search_terms.c.term_id==term.term_id).\
values(lock=True)
conn.execute(lock_terms)
if trans.commit():
<do things with the search terms>
except:
trans.rollback()The problem is the SQL query generated by the select code above is not FOR SHARE, it's FOR UPDATE:
SELECT search_terms.term_id, search_terms.term
FROM search_terms
WHERE search_terms.lock = :lock_1 AND search_terms.status = :status_1
ORDER BY search_terms.term
LIMIT :param_1 FOR UPDATEAccording to the SQLAlchemy API docs, under the "for_update" parameter description:
With the Postgresql dialect, the values “read” and "read_nowait" translate to FOR SHARE and FOR SHARE NOWAIT, respectively.
According to the above, the compiled SQL statement should be FOR SHARE, but it is not. Where is the error in my code?
If you have a good answer, please also answer it on stackoverflow
--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/wmFM_7UILRoJ.
To post to this group, send email to sqlal...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
The problem is the SQL query generated by the select code above is not FOR SHARE, it's FOR UPDATE:
SELECT search_terms.term_id, search_terms.term FROM search_terms WHERE search_terms.lock = :lock_1 AND search_terms.status = :status_1 ORDER BY search_terms.term LIMIT :param_1 FOR UPDATE