]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
implement independent CTEs
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 12 Jul 2021 18:28:19 +0000 (14:28 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 12 Jul 2021 21:10:58 +0000 (17:10 -0400)
commit204ff1f60cf911b00b7494942fc58bc715dddeed
treef26659888176bfaed484f6f462efd0414542633a
parentca52e87268fec966f6005b1e4aa30206ae895e9e
implement independent CTEs

Added new method :meth:`_sql.HasCTE.add_cte` to each of the
:func:`_sql.select`, :func:`_sql.insert`, :func:`_sql.update` and
:func:`_sql.delete` constructs. This method will add the given
:class:`_sql.CTE` as an "independent" CTE of the statement, meaning it
renders in the WITH clause above the statement unconditionally even if it
is not otherwise referenced in the primary statement. This is a popular use
case on the PostgreSQL database where a CTE is used for a DML statement
that runs against database rows independently of the primary statement.

Fixes: #6752
Change-Id: Ibf635763e40269cbd10f4c17e208850d8e8d0188
doc/build/changelog/unreleased_14/6752.rst [new file with mode: 0644]
lib/sqlalchemy/sql/coercions.py
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/sql/crud.py
lib/sqlalchemy/sql/dml.py
lib/sqlalchemy/sql/roles.py
lib/sqlalchemy/sql/selectable.py
test/dialect/postgresql/test_compiler.py
test/sql/test_compare.py
test/sql/test_cte.py