for_update=whatever always creates a "FOR UPDATE" query

Issue #2731 resolved
Fayaz Yusuf Khan created an issue

When using

table.select(for_update='read')

The query string representation is still

SELECT "user".id 
FROM "user" FOR UPDATE

Comments (2)

  1. Mike Bayer repo owner

    the docs state here that these behaviors are dialect specific:

    http://docs.sqlalchemy.org/en/rel_0_8/core/expression_api.html?highlight=for_update#sqlalchemy.sql.expression.select

    for_update=False –

    when True, applies FOR UPDATE to the end of the resulting statement.

    Certain database dialects also support alternate values for this parameter:
    
        With the MySQL dialect, the value "read" translates to LOCK IN SHARE MODE.
        With the Oracle and Postgresql dialects, the value "nowait" translates to FOR UPDATE NOWAIT.
        With the Postgresql dialect, the values read and "read_nowait" translate to FOR SHARE and FOR SHARE NOWAIT, respectively.
    

    so here the behavior requires a mysql dialect:

    from sqlalchemy import *
    from sqlalchemy.dialects import mysql
    
    def test():
        table = Table('user', MetaData(), Column('id', Integer, primary_key=True))
        query = table.select(for_update='read')
        assert "LOCK IN SHARE MODE" in str(query.compile(dialect=mysql.dialect()))
    
    
    if __name__ == '__main__':
        test()
    
  2. Log in to comment