On Thu, Feb 23, 2023, at 10:44 PM, [email protected] wrote: > Hello, > > In order to use the PostgreSQL LOCK > <https://www.postgresql.org/docs/14/sql-lock.html> with SQLAlchemy, is there > a better way than > > *session.execute(sa.text(f"LOCK TABLE {Foo.__tablename__} IN SHARE MODE"))*
I would probably use session.connection().exec_driver_sql() for more succinctness. if you want to build a custom SQL construct you can check out @compiles at https://docs.sqlalchemy.org/en/20/core/compiler.html > > > Also, do I need to *flush()* to push the LOCK to the db? not at all, execute() as well as connection().execute(), connection().exec_driver_sql() push the given SQL right out, which you can see by adding echo=True to your create_engine(). > > Much thanks! > Jens > > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/0cfe4a51-f013-4299-a584-9ddb643bc906n%40googlegroups.com > > <https://groups.google.com/d/msgid/sqlalchemy/0cfe4a51-f013-4299-a584-9ddb643bc906n%40googlegroups.com?utm_medium=email&utm_source=footer>. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/af027a75-109a-4eb5-abbe-20f7fe29cf9e%40app.fastmail.com.
