2189 Commits

Author SHA1 Message Date
abdallah elhdad 7d3b4f9049 Add JSON type support for Oracle dialect
Added support for the :class:`_sqltypes.JSON` datatype when using the
Oracle database with the oracledb dialect.  JSON values are serialized and
deserialized using configurable strategies that accommodate Oracle's native
JSON type available as of Oracle 21c.  Pull request courtesy Abdallah
Alhadad.

This fix also includes new dialect-level indicators for JSON support;
some attention given to issue #13213 indicates we can close that issue.

Fixes: #10375
Closes: #13065
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/13065
Pull-request-sha: 9a89237f4f

Change-Id: I8cbe35bc632dc9419642ddca8bf4ba9c20c0ae37
2026-04-03 14:53:53 -04:00
bekapono 9ad90693bc Coercion warning feedback for unary distinct outside aggregate function
A warning is emitted when using the standalone :func:`_.sql.distinct`
function in a :func:`_sql.select` columns list outside of an aggregate
function; this function is not intended as a replacement for the use of
:meth:`.Select.distinct`. Pull request courtesy bekapono.

Fixes: #11526
Closes: #13162
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/13162
Pull-request-sha: c6e8be7a49

Change-Id: Ibbdd64a922c62a7a9ead566590ad854db4066565
2026-03-31 10:45:18 -04:00
Michael Bayer 38e0fc2dd0 Merge "Add frame exclusion support for window functions" into main 2026-03-23 12:29:36 +00:00
Varun Chawla 30880dbd8e Add frame exclusion support for window functions
Add the `exclude` parameter to the `Over` construct and all `.over()`
methods, enabling SQL standard frame exclusion clauses
`EXCLUDE CURRENT ROW`, `EXCLUDE GROUP`, `EXCLUDE TIES`,
`EXCLUDE NO OTHERS` in window functions.
Pull request courtesy of Varun Chawla.

Fixes #11671
Closes: #13117
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/13117
Pull-request-sha: 23f9d34dd8

Change-Id: I8efdb06876d5a11a9f5ed9abec2c187c6c9b7e5e
2026-03-16 20:26:11 +00:00
Federico Caselli b0b74dc965 Improve typing story for core from clauses.
Most :class:`_sql.FromClause` subclasses are not generic on
:class:`.TypedColumns` subclasses, that can be used to type their
:attr:`_sql.FromClause.c` collection.
This applied to :class:`_schema.Table`, :class:`_sql.Join`,
:class:`_sql.Subquery`, :class:`_sql.CTE` and more.

Fixes: #13085
Change-Id: I724aca887a85c4a401df875903eda12125066680
2026-03-12 23:02:30 +01:00
Federico Caselli b1e299b94a Omit metadata kw from Enum repr
Do not render metadata in the repr of enum.

Change-Id: Ic65e9572ff24af8d48e15277cbc824f7c5ce845a
References: #10604
2026-02-24 16:32:56 +00:00
Michael Bayer 9440b55b17 Merge "allow TypeEngine classes to export their repr() parameters" into main 2026-02-24 16:31:11 +00:00
Mike Bayer d70c040a95 allow TypeEngine classes to export their repr() parameters
Added a new :class:`.GenericRepr` class and :meth:`.TypeEngine.repr_struct`
method to provide better control over type representation. The
:class:`.TypeDecorator` class now properly displays its decorated type's
parameters in its ``__repr__()``, allowing introspection tools and
libraries like Alembic to better understand the structure of decorated
types, in particular for complex "schema" types such as :class:`.Enum` and
:class:`.Boolean`. Type classes can override
:meth:`.TypeEngine.repr_struct` to customize their representation
structure, and the returned :class:`.GenericRepr` object allows for
modifications such as changing the displayed class name.

Fixes: #13140
Change-Id: Ie41d249cfea56686b16c895b74ae03721207170b
2026-02-24 11:10:52 -05:00
Tiansu Yu 8c26205124 Mysql ddl compiler fall back to default index args
Fixed issue where DDL compilation options were registered to the hard-coded
dialect name ``mysql``. This made it awkward for MySQL-derived dialects
like MariaDB, StarRocks, etc. to work with such options when different sets
of options exist for different platforms. Options are now registered under
the actual dialect name, and a fallback was added to help avoid errors when
an option does not exist for that dialect. Pull request courtesy Tiansu Yu.

Fixes: #13134

Closes: #13138
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/13138
Pull-request-sha: 1bc953a2a1

Change-Id: Ifa700a4e34da4d1923e9473dd8f0d2417dcfded4
2026-02-23 13:21:47 -05:00
Michael Bayer f5b89a27d6 Merge "allow batch with upsert if embed_values_counter is True" into main 2026-02-06 15:06:37 +00:00
Mike Bayer abaeb00888 fix failing test
the new addition of c names like "add" "extend" test
needed to be adjusted to target a single dialect

Change-Id: I94ab20314c8bc312135706ecc3d9aaad89b3caf4
2026-02-05 11:47:07 -05:00
Mike Bayer 574facaaf4 allow batch with upsert if embed_values_counter is True
Fixed issue in the :ref:`engine_insertmanyvalues` feature where using
PostgreSQL's ``ON CONFLICT`` clause with
:paramref:`_dml.Insert.returning.sort_by_parameter_order` enabled would
generate invalid SQL when the insert used an implicit sentinel (server-side
autoincrement primary key). The generated SQL would incorrectly declare a
sentinel counter column in the ``imp_sen`` table alias without providing
corresponding values in the ``VALUES`` clause, leading to a
``ProgrammingError`` indicating column count mismatch. The fix allows batch
execution mode when ``embed_values_counter`` is active, as the embedded
counter provides the ordering capability needed even with upsert behaviors,
rather than unnecessarily downgrading to row-at-a-time execution.

Fixes: #13107
Change-Id: I382472b2cf2991b520344adea5783584e27425d0
2026-02-05 10:09:09 -05:00
Mike Bayer eff50d9e9b split ReadOnlyColumnCollection from writeable methods
The :class:`.ColumnCollection` class hierarchy has been refactored to allow
column names such as ``add``, ``remove``, ``update``, ``extend``, and
``clear`` to be used without conflicts. :class:`.ColumnCollection` is now
an abstract base class, with mutation operations moved to
:class:`.WriteableColumnCollection` and :class:`.DedupeColumnCollection`
subclasses. The :class:`.ReadOnlyColumnCollection` exposed as attributes
such as :attr:`.Table.c` no longer includes mutation methods that raised
:class:`.NotImplementedError`, allowing these common column names to be
accessed naturally, e.g. ``table.c.add``, ``table.c.remove``,
``table.c.update``, etc.

Change-Id: I22da8314fe7c451003e948d774040d86901bbca4
2026-01-30 09:59:36 -05:00
Mike Bayer 1dc49abfea change float -> Double in the _type_map.
The :class:`.Double` type is now used when a Python float value is detected
as a literal value to be sent as a bound parameter, rather than the
:class:`.Float` type.  :class:`.Double` has the same implementation as
:class:`.Float`, but when rendered in a CAST, produces ``DOUBLE`` or
``DOUBLE PRECISION`` rather than ``FLOAT``.   The former better matches
Python's ``float`` datatype which uses 8-byte double-precision storage.
Third party dialects which don't support the :class:`.Double` type directly
may need adjustment so that they render an appropriate keyword (e.g.
``FLOAT``) when the :class:`.Double` datatype is encountered.

Fixes: #10300
Change-Id: I6d221ca9206a10c73fefad55f7ab7a6da5c81d6b
2026-01-20 20:31:41 -05:00
Federico Caselli 8e90bfd9b4 Deprecate DropConstraint.isolate_from_table
The the parameter :paramref:`_schema.DropConstraint.isolate_from_table`
was deprecated since it has no effect on the drop table behavior.
Its default values was also changed to ``False``.

Fixes: #13006
Change-Id: Ibaa68e78da301a4f2a200f8c7abb2dc099fef37a
2026-01-12 22:12:17 +01:00
Fardin Alizadeh 81e72ca9cd fix typos (#13047)
* fix typos

* fix typos

* fix typos

---------

Co-authored-by: fardyn <fa.alizadeh@pm.me>
2025-12-19 21:24:23 +01:00
Fardin Alizadeh fb408b8e9d fix typos (#13038)
* fix typos

* fix typos

---------

Co-authored-by: fardyn <fa.alizadeh@pm.me>
2025-12-18 21:18:42 +01:00
Mike Bayer 3988071d0d update default driver for oracle, postgresql
The default DBAPI driver for the Oracle Database dialect has been changed
to ``oracledb`` instead of ``cx_oracle``. The ``cx_oracle`` driver remains
fully supported and can be explicitly specified in the connection URL
using ``oracle+cx_oracle://``.

The default DBAPI driver for the PostgreSQL dialect has been changed to
``psycopg`` (psycopg version 3) instead of ``psycopg2``. The ``psycopg2``
driver remains fully supported and can be explicitly specified in the
connection URL using ``postgresql+psycopg2://``.

Fixes: #13010
Change-Id: Ie75810f4c3af609d20da63289d2662dfa2385ca2
2025-12-15 23:01:12 -05:00
G Allajmi 9fe3c3cd30 Factor out constraints into separate methods
Fixed issue where PostgreSQL dialect options such as ``postgresql_include``
on :class:`.PrimaryKeyConstraint` and :class:`.UniqueConstraint` were
rendered in the wrong position when combined with constraint deferrability
options like ``deferrable=True``. Pull request courtesy G Allajmi.

Fixes: #12867
Closes: #13003
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/13003
Pull-request-sha: 1a9216062f

Change-Id: I8c55d8faae25d56ff63c9126d569c01d8ee6c7dd
2025-12-09 15:12:34 -05:00
Mike Bayer 9a0d004331 filter_by works across multiple entities
The :meth:`_sql.Select.filter_by`, :meth:`_sql.Update.filter_by` and
:meth:`_sql.Delete.filter_by` methods now search across all entities
present in the statement, rather than limiting their search to only the
last joined entity or the first FROM entity. This allows these methods
to locate attributes unambiguously across multiple joined tables,
resolving issues where changing the order of operations such as
:meth:`_sql.Select.with_only_columns` would cause the method to fail.

If an attribute name exists in more than one FROM clause entity, an
:class:`_exc.AmbiguousColumnError` is now raised, indicating that
:meth:`_sql.Select.filter` (or :meth:`_sql.Select.where`) should be used
instead with explicit table-qualified column references.

Fixes: #8601
Change-Id: I6a46b8f4784801f95f7980ca8ef92f1947653572
2025-12-04 13:53:27 +00:00
Mike Bayer a9e82a6abe block json tests for non-json backends
these were failing on Oracle which has no json type

Change-Id: I3c35c4f38c581378c74ee9dc3fb7a71655c5ee9c
2025-12-02 23:18:58 -05:00
Mike Bayer b9e3cacb0e add TString support
Added support for Python 3.14+ template strings (t-strings) via the new
:func:`_sql.tstring` construct, as defined in :pep:`750`. This feature
allows for ergonomic SQL statement construction by automatically
interpolating Python values and SQLAlchemy expressions within template
strings.

Part of the challenge here is the syntax only works on py314, so we have
to exclude the test file at many levels when py314 is not used.  not
sure yet how i want to adjust pep8 tests and rules for this.

Fixes: #12548
Change-Id: Ia060d1387ff452fe4f5d924f683529a22a8e1f72
2025-11-30 14:38:13 -05:00
Mike Bayer 3d6a109c83 drop a 400 ton anvil on oracle 23c
this DB is extremely erratic in being able to connect.   Add
a brute force connection retrier to all engines everywhere
(which for oracledb we can fortunately use their built-in feature
that also works).
This actually works and I can see it pausing under load, reconnecting,
and succeeding.  the problem is that absolutely every engine everywhere
needs this routine otherwise an engine without a retrier in it will
crash.    That then necessitates digging into testing_engine(),
making sure testing_engine() is used everywhere an engine that's going
to connect is used, then dealing with the fallout from that.

We also simplify some older workarounds for cx_oracle and
hack into config/provision to make oracledb seem like the primary
DBAPI for most tests.

testing_engine has been completely overhauled, making use of a new
post_configure_testing_engine() hook which moves and refines
the SQLite pool sharing and savepoint logic all into sqlite/provision.py
and also allows for cx_oracle to apply a retry event handler.

Change-Id: I4ea4c523effb878290d28b94d8925eb32fc5ae3b
2025-11-28 13:16:13 -05:00
Mike Bayer cf62005639 test oracle 23c, mariadb12; reduce backend use
one particular vector test wont run on oracle 23c free, so
just disable it.

added better skips for the rest of the vector tests and
fixed a deprecation issue.

this will be the first run on the new oracle23 on CI so we'll have to
see how this goes.

Also adjust for mariabdb12 being overly helpful with regards
to stale row updates.

as we are having trouble getting 23c to pass throug transaction
tests, i noted we have an explosion of tests due to the multiple
drivers, so this patch introduces __sparse_driver_backend__
for all tests where we want variety of
database server but there's no need to test every driver.
This should dramatically reduce the size of the test suite run

Change-Id: Ic8d3eb0a60e76b4c54c6bb4a721f90c81ede782b
2025-11-25 14:50:56 -05:00
Mike Bayer 42710c9220 propagate _scalar_type() for SelectStatementGrouping
Fixed issue where using the :meth:`.ColumnOperators.in_` operator with a
nested :class:`.CompoundSelect` statement (e.g. an ``INTERSECT`` of
``UNION`` queries) would raise a :class:`NotImplementedError` when the
nested compound select was the first argument to the outer compound select.
The ``_scalar_type()`` internal method now properly handles nested compound
selects.

Fixes: #12987
Change-Id: I6aa1b38863588d371bbac74b3531b99ccd5fcaec
2025-11-18 15:11:05 -05:00
Albert N 95ab6ed79c perf tuning of BaseRow
common cases are a bit faster overall

Python version
|                      | python opt | python main | py opt / main |
| -------------------- | ---------- | ----------- | ------------- |
| base_row_new         | 0.84959    | 0.86417     | 0.9831283197  |
| row_new              | 0.85698    | 0.85543     | 1.001811954   |
| base_row_new_proc    | 2.77489    | 2.81795     | 0.9847193882  |
| row_new_proc         | 2.77881    | 2.86206     | 0.9709125595  |
| brow_new_proc_none   | 1.6311     | 1.65773     | 0.9839358641  |
| row_new_proc_none    | 1.65048    | 1.69896     | 0.9714648962  |
| row_dumps            | 0.15279    | 0.14519     | 1.052345203   |
| row_loads            | 0.91471    | 0.91358     | 1.001236892   |
| row_values_impl      | 0.1818     | 0.17773     | 1.022899904   |
| row_iter             | 0.44042    | 0.4554      | 0.967105841   |
| row_len              | 0.13858    | 0.13079     | 1.059561129   |
| row_hash             | 0.28614    | 0.29172     | 0.9808720691  |
| getitem              | 0.23159    | 0.23138     | 1.000907598   |
| getitem_slice        | 0.38393    | 0.38765     | 0.9904037147  |
| get_by_key           | 0.33692    | 0.33913     | 0.993483325   |
| get_by_key2          | 0.35105    | 0.33915     | 1.035087719   |
| getattr              | 0.46809    | 0.46911     | 0.9978256699  |
| get_by_key_recreate  | 1.08137    | 1.18224     | 0.9146789146  |
| get_by_key_recreate2 | 0.98543    | 0.99272     | 0.9926565396  |
| getattr_recreate     | 0.74       | 0.7407      | 0.999054948   |
| contains             | 0.49312    | 0.74477     | 0.6621104502  |

Cython version
|                      | cython opt | cython main | cy opt / main |
| -------------------- | ---------- | ----------- | ------------- |
| base_row_new         | 0.12933    | 0.1347      | 0.9601336303  |
| row_new              | 0.15755    | 0.16489     | 0.9554854752  |
| base_row_new_proc    | 0.87398    | 1.08483     | 0.8056377497  |
| row_new_proc         | 0.88592    | 1.13255     | 0.7822347799  |
| brow_new_proc_none   | 0.2664     | 0.41703     | 0.6388029638  |
| row_new_proc_none    | 0.27526    | 0.42483     | 0.6479297601  |
| row_dumps            | 0.37526    | 0.20093     | 1.867615588   |
| row_loads            | 0.53037    | 0.3607      | 1.470390907   |
| row_values_impl      | 0.36886    | 0.22218     | 1.660185435   |
| row_iter             | 0.25249    | 0.25553     | 0.9881031581  |
| row_len              | 0.05194    | 0.05412     | 0.9597191426  |
| row_hash             | 0.18864    | 0.18726     | 1.007369433   |
| getitem              | 0.13876    | 0.13934     | 0.9958375197  |
| getitem_slice        | 0.23181    | 0.2318      | 1.000043141   |
| get_by_key           | 0.17031    | 0.17857     | 0.9537436299  |
| get_by_key2          | 0.58172    | 0.31651     | 1.837919813   |
| getattr              | 0.21275    | 1.16669     | 0.1823534958  |
| get_by_key_recreate  | 0.80161    | 0.8836      | 0.9072091444  |
| get_by_key_recreate2 | 1.14649    | 0.98709     | 1.161484768   |
| getattr_recreate     | 0.55927    | 1.09921     | 0.5087926784  |
| contains             | 0.35338    | 0.5494      | 0.6432107754  |

Closes: #12919
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12919
Pull-request-sha: b13204b741

Change-Id: I5ff2b951f9840e99abdad3ae286ecb8becc70e4b
2025-11-13 23:59:59 +01:00
Michael Bayer ebd118a1a2 Merge "Add DDL association to Table, CreateView support" into main 2025-11-11 14:48:55 +00:00
Federico Caselli 33264146ae Improve params implementation
Added new implementation for the :meth:`.Select.params` method and that of
similar statements, via a new statement-only
:meth:`.ExecutableStatement.params` method which works more efficiently and
correctly than the previous implementations available from
:class:`.ClauseElement`, by assocating the given parameter dictionary with
the statement overall rather than cloning the statement and rewriting its
bound parameters.  The :meth:`_sql.ClauseElement.params` and
:meth:`_sql.ClauseElement.unique_params` methods, when called on an object
that does not implement :class:`.ExecutableStatement`, will continue to
work the old way of cloning the object, and will emit a deprecation
warning.    This issue both resolves the architectural / performance
concerns of 🎫`7066` and also provides correct ORM compatibility for
functions like :func:`_orm.aliased`, reported by 🎫`12915`.

Fixes: #7066
Change-Id: I6543c7d0f4da3232b3641fb172c24c446f02f52a
2025-11-10 16:50:54 -05:00
Michael Bayer 59f29eef15 Merge "Allow non-integer RANGE in OVER" into main 2025-11-08 19:58:00 +00:00
Mike Bayer 98361f19a8 Add DDL association to Table, CreateView support
Added support for the SQL ``CREATE VIEW`` statement via the new
:class:`.CreateView` DDL class. The new class allows creating database
views from SELECT statements, with support for options such as
``TEMPORARY``, ``IF NOT EXISTS``, and ``MATERIALIZED`` where supported by
the target database. Views defined with :class:`.CreateView` integrate with
:class:`.MetaData` for automated DDL generation and provide a
:class:`.Table` object for querying.

this alters the CreateTableAs commit:

* adds the ability for Table to be associated with Create and Drop
  DDL constructs
* Adds CreateView variant of CreateTableAs
* Both associate themselves with Table so they take place in
  create_all/create/drop_all/drop

Fixes: #181
Change-Id: If3e568d3d6a6ce19e3d15198c3fbbe06bd847c83
2025-11-08 13:42:15 -05:00
Mike Bayer 143d2a78c7 support subscript for hstore
Added support for PostgreSQL 14+ HSTORE subscripting syntax. When connected
to PostgreSQL 14 or later, HSTORE columns now automatically use the native
subscript notation ``hstore_col['key']`` instead of the arrow operator
``hstore_col -> 'key'`` for both read and write operations. This provides
better compatibility with PostgreSQL's native HSTORE subscripting feature
while maintaining backward compatibility with older PostgreSQL versions.

as part of this change we add a new parameter to custom_op "visit_name"
which allows a custom op to refer to a specific visit method in a
dialect's compiler.

Fixes: #12948
Change-Id: Id98d333fe78e31d9c7679cb2902f1c7e458d6e11
2025-10-31 21:11:49 -04:00
Mike Bayer 293af0439d more cache_key coverage
Change-Id: I68ed84c1617b4d15b0103cf4a3debd1da05c6c97
2025-10-27 12:18:56 -04:00
Mike Bayer 3db9c6be2d try to improve coverage a bit
use pyproject.toml so the options are safe from "rm .coverage*"
types of commands

omit some files

add test coverage for a big section of cache-key

Change-Id: Ia540c632d91ec09284e187e3edeb8ccf0214e1a6
2025-10-27 10:56:49 -04:00
Mike Bayer a5ccd8e9ef repair / modernize binary literal round trip test
update this test to use modern literal round trip
now that execute_compiled is gone

Fixes: #12940
Change-Id: I587dc6845fa8ff078baf3f6e08e54ce6cec84630
2025-10-26 09:43:21 -04:00
Michael Bayer 3eb9308def Merge "Support for Create Table As" into main 2025-10-25 20:18:32 +00:00
Greg Jarzab 7f5e9e733c Support for Create Table As
Added support for the SQL ``CREATE TABLE ... AS SELECT`` construct via the
new :class:`_sql.CreateTableAs` DDL construct and the
:meth:`_sql.SelectBase.into` method. The new construct allows creating a
table directly from the results of a SELECT statement, with support for
options such as ``TEMPORARY`` and ``IF NOT EXISTS`` where supported by the
target database.  Pull request courtesy Greg Jarzab.

Fixes: #4950
Closes: #12860
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12860
Pull-request-sha: 7de8a109b8

Change-Id: Id9c8e4a3c520ffc61de1e48e331b6220e3d52fc9
2025-10-25 14:24:46 -04:00
Federico Caselli 413a87093c postfix of I5f0fe800e31aac052926cebe9206763eef9a804c
Change-Id: Ic007a5bd842207a2c5a56374953e48c6acc7b254
2025-10-24 23:54:48 +02:00
Violet Folino Gallo f9acbeb778 Allow non-integer RANGE in OVER
Updated the :func:`_sql.over` clause to allow non-integer values in
:paramref:`_sql.over.range_` clause. Previously, only integer values
were allowed and any other values would lead to a failure.
To specify a non-integer value, use the new :class:`_sql.FrameClause`
construct along with the new :class:`_sql.FrameClauseType` enum to specify
the frame boundaries.

Fixes #12596.
Closes: #12695
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12695
Pull-request-sha: 8063cec65d

Change-Id: I248a938f6502d72555c005d86791c992822117d4
2025-10-24 23:10:01 +02:00
Mike Bayer 87e27693ad proposal: remove _execute_compiled()
this isn't used internally and only allows execute(stmt.compile())
to work, which is not something I want to support.

Since people are definitely using this [1] we might want to think about
either deprectation or having a recipe for people who really want
to still do this

[1] https://github.com/sqlalchemy/sqlalchemy/discussions/11108?converting=1

Change-Id: I5f0fe800e31aac052926cebe9206763eef9a804c
2025-10-23 21:38:15 +02:00
Mike Bayer 6023557539 ensure explicit left side considered for ON clause in join_from
Fixed an issue in :meth:`_sql.Select.join_from` where the join condition
between the left and right tables specified in the method call could be
incorrectly determined based on an intermediate table already present in
the FROM clause, rather than matching the foreign keys between the
immediate left and right arguments. The join condition is now determined by
matching primary keys between the two tables explicitly passed to
:meth:`_sql.Select.join_from`, ensuring consistent and predictable join
behavior regardless of the order of join operations or other tables present
in the query.  The fix is applied to both the Core and ORM implementations
of :meth:`_sql.Select.join_from`.

Fixes: #12931
Change-Id: Id457d441ee8a1bd64a002e57a9dcfd6fc56ff15e
2025-10-21 09:21:29 -04:00
Mike Bayer b8906e62ce re-document 12915 as not fully fixed
The ORM side of this issue can't be fixed without rewriting
.params() which will be 2.1 only, so clarify changelog

References: #12915
Change-Id: I2e524d5390241aa289786f524b6a51f39bc09876
2025-10-17 08:57:10 -04:00
Mike Bayer 03116b8cc9 fully copy_internals for AnnotatedFromClause for straight cloned traverse
Fixed issue where using :meth:`_sql.Select.params` to replace bound
parameters in a query could fail for some cases where the parameters
were embedded in subqueries or CTEs when ORM classes were involved,
due to issues with internal query traversal for these cases.

Fixes: #12915
Change-Id: Ib63bca786a541682f6b2144fd5dd43350411ae9d
2025-10-15 15:21:08 -04:00
Mike Bayer 148059ced6 Add Executable traverse internals to Executable subclasses and turn tests on
Fixed a caching issue where :func:`_orm.with_loader_criteria` would
incorrectly reuse cached bound parameter values when used with
:class:`_sql.CompoundSelect` constructs such as :func:`_sql.union`. The
issue was caused by the cache key for compound selects not including the
execution options that are part of the :class:`_sql.Executable` base class,
which :func:`_orm.with_loader_criteria` uses to apply its criteria
dynamically. The fix ensures that compound selects and other executable
constructs properly include execution options in their cache key traversal.

Fixes: #12905
Change-Id: I24bbd96233cddabe42eb716f078eea4c84b1af05
2025-10-08 08:47:24 -04:00
Michael Bayer a8a6972420 Merge "Add explicit multi-threaded tests and support free-threaded build" into main 2025-10-07 13:17:08 +00:00
Lysandros Nikolaou 456727df50 Add explicit multi-threaded tests and support free-threaded build
Implemented initial support for free-threaded Python by adding new tests
and reworking the test harness and GitHub Actions to include Python 3.13t
and Python 3.14t in test runs. Two concurrency issues have been identified
and fixed: the first involves initialization of the ``.c`` collection on a
``FromClause``, a continuation of 🎫`12302`, where an optional mutex
under free-threading is added; the second involves synchronization of the
pool "first_connect" event, which first received thread synchronization in
🎫`2964`, however under free-threading the creation of the mutex
itself runs under the same free-threading mutex. Initial pull request and
test suite courtesy Lysandros Nikolaou.

py313t: yes
py314t: yes
Fixes: #12881
Closes: #12882
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12882
Pull-request-sha: 53d65d96b9

Co-authored-by: Mike Bayer <mike_mp@zzzcomputng.com>
Change-Id: I2e4f2e9ac974ab6382cb0520cc446b396d9680a6
2025-10-02 12:14:28 -04:00
Federico Caselli e688617c92 deprecate inherit_schema argument
Named types such as :class:`_postgresql.ENUM` and
:class:`_postgresql.DOMAIN` (as well as the dialect-agnostic
:class:`_types.Enum` version) are now more strongly associated with the
:class:`_schema.MetaData` at the top of the table hierarchy and are
de-associated with any particular :class:`_schema.Table` they may be a part
of. This better represents how PostgreSQL named types exist independently
of any particular table, and that they may be used across many tables
simultaneously.  The change impacts the behavior of the "default schema"
for a named type, as well as the CREATE/DROP behavior in relationship to
the :class:`.MetaData` and :class:`.Table` construct.  The change also
includes a new :class:`.CheckFirst` enumeration which allows fine grained
control over "check" queries during DDL operations, as well as that the
:paramref:`_types.SchemaType.inherit_schema` parameter is deprecated and
will emit a deprecation warning when used.  See the migration notes for
full details.

Fixes: #12690
Change-Id: I9752a9d52774ae760ec3448f62fc5046c58d68f5
2025-09-24 16:33:58 -04:00
Mike Bayer efd49a19a4 deprecate ARRAY.any(), ARRAY.all(), postgresql.Any(), postgresql.All()
The :meth:`_types.ARRAY.Comparator.any` and
:meth:`_types.ARRAY.Comparator.all` methods for the :class:`_types.ARRAY`
type are now deprecated for removal; these two methods along with
:func:`_postgresql.Any` and :func:`_postgresql.All` have been legacy for
some time as they are superseded by the :func:`_sql.any_` and
:func:`_sql.all_` functions, which feature more intutive use.

Fixes: #10821
Change-Id: I8eb3bbcb98af4ee60a21767dc3bdac771cbc0b4c
2025-09-20 16:39:28 -04:00
Mike Bayer aaa85f707e Use ARRAY type for any_(), all_() coercion
Fixed issue where the :func:`_sql.any_` and :func:`_sql.all_` aggregation
operators would not correctly coerce the datatype of the compared value, in
those cases where the compared value were not a simple int/str etc., such
as a Python ``Enum`` or other custom value.   This would lead to execution
time errors for these values.  This issue is essentially the same as
🎫`6515` which was for the now-legacy :meth:`.ARRAY.any` and
:meth:`.ARRAY.all` methods.

Fixes: #12874
Change-Id: I980894c23b9974bc84d584a1a4c5fae72dded6d3
2025-09-20 14:24:48 -04:00
Mike Bayer 9a6854223c fix tests for aggregate_order_by
forgot this doesnt work on sqlite older than 3.44

Change-Id: Icebc2ffaceb078a436a8f61ba583bc05b77f680d
2025-09-19 15:18:39 -04:00
Reuven Starodubski 459ebc668a Add FunctionElement.aggregate_order_by
Added new generalized aggregate function ordering to functions via the
:func:`_functions.FunctionElement.aggregate_order_by` method, which
receives an expression and generates the appropriate embedded "ORDER BY" or
"WITHIN GROUP (ORDER BY)" phrase depending on backend database.  This new
function supersedes the use of the PostgreSQL
:func:`_postgresql.aggregate_order_by` function, which remains present for
backward compatibility.   To complement the new parameter, the
:paramref:`_functions.aggregate_strings.order_by` which adds ORDER BY
capability to the :class:`_functions.aggregate_strings` dialect-agnostic
function which works for all included backends. Thanks much to Reuven
Starodubski with help on this patch.

Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com>
Fixes: #12853
Closes: #12856
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12856
Pull-request-sha: d93fb591751227eb1f96052ea3ad449f511f70b3

Change-Id: I8eb41ff2d57695963a358b5f0017ca9372f15f70
2025-09-19 09:38:57 -04:00