On Mon, Jan 20, 2020, at 2:26 PM, Mike Bayer wrote: > > > On Mon, Jan 20, 2020, at 1:46 PM, Andrei Pashkin wrote: >> Hello! >> >> I wonder - is it possible to parametrize where expression as a whole like >> that: >> select([users_table]).where(bindparam('criteria')) > > nope, that's not how SQL bound parameters work. > >> >> ? >> >> My use case is that I'd like to pre-compile a complex SQLAlchemy expression >> to avoid redundant computations and achieve the same effect as Bakery has >> for the ORM but only for a low-level SA expression. > > Wait for SQLAlchemy 1.4, this will have that feature.
noting also, there is a cache feature for Core statements right now, you just have to use the same statement object each time, since currently the statement object itself is the cache key. See https://docs.sqlalchemy.org/en/13/core/connections.html?highlight=compiled_cache#sqlalchemy.engine.Connection.execution_options.params.compiled_cache . This is what BakedQuery ultimately uses also and the unit of work uses it also. In 1.4 all statements will be able to generate a separate cache key that is repeatable for multiple instances of the same statement. > > > > >> >> >> >> >> -- >> 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 sqlalchemy+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/sqlalchemy/c6a93f06-7ec4-4a00-bc8b-4e34f58e28ac%40googlegroups.com >> >> <https://groups.google.com/d/msgid/sqlalchemy/c6a93f06-7ec4-4a00-bc8b-4e34f58e28ac%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 sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/55474455-b40c-4453-80bd-a56ae9e876db%40www.fastmail.com.