Commit Graph

2171 Commits

Author SHA1 Message Date
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
Michael Bayer 922f24cb60 Merge "add OperatorClasses to gate mismatched operator use" into main 2025-08-31 14:18:56 +00:00
Mike Bayer 4c4011b50b use _generate_columns_plus_names for ddl returning c populate
Improved the implementation of :meth:`.UpdateBase.returning` to use more
robust logic in setting up the ``.c`` collection of a derived statement
such as a CTE.  This fixes issues related to RETURNING clauses that feature
expressions based on returned columns with or without qualifying labels.

Co-authored-by: Juhyeong Ko <dury.ko@gmail.com>
Fixes: #12271
Change-Id: Id0d486d4304002f1affdec2e7662ac2965936f2a
2025-08-26 18:13:46 -04:00
Mike Bayer 34740d33ab add OperatorClasses to gate mismatched operator use
Added a new concept of "operator classes" to the SQL operators supported by
SQLAlchemy, represented within the enum :class:`.OperatorClass`.  The
purpose of this structure is to provide an extra layer of validation when a
particular kind of SQL operation is used with a particular datatype, to
catch early the use of an operator that does not have any relevance to the
datatype in use; a simple example is an integer or numeric column used with
a "string match" operator.

Fixes: #12736
Change-Id: I44f46d7326aef6847dbf0cf7a325833f8e347da6
2025-08-25 16:47:24 -04:00
Mike Bayer 3e5f4d63b5 more extensibility for asc/desc
Improved the behavior of standalone "operators" like :func:`_sql.desc`,
:func:`_sql.asc`, :func:`_sql.all_`, etc. so that they consult the given
expression object for an overriding method for that operator, even if the
object is not itself a ``ClauseElement``, such as if it's an ORM attribute.
This allows custom comparators for things like :func:`_orm.composite` to
provide custom implementations of methods like ``desc()``, ``asc()``, etc.

Added default implementations of :meth:`.ColumnOperators.desc`,
:meth:`.ColumnOperators.asc`, :meth:`.ColumnOperators.nulls_first`,
:meth:`.ColumnOperators.nulls_last` to :func:`_orm.composite` attributes,
by default applying the modifier to all contained columns.  Can be
overridden using a custom comparator.

Fixes: #12769
Change-Id: I055ce79bf7ac31fb61d48bc3ab34799d42fb6336
2025-08-22 18:05:48 +00:00
Michael Bayer ec4d3a67fd Merge "add CRUD column marker" into main 2025-08-04 19:41:56 +00:00
Michael Bayer 0d2dc3afde Merge "Improve handling of sentinel columns" into main 2025-07-19 11:09:50 +00:00
Federico Caselli 320c3b5b04 add recursive test to values cte
Change-Id: I544aab7f9f5d2640fc6c3d970d835a6e3f80d746
2025-07-15 22:52:05 +02:00
Mike Bayer 209d1913cc extend Values from HasCTE
The :func:`_sql.values` construct gains a new method :meth:`_sql.Values.cte`,
which allows creation of a named, explicit-columns :class:`.CTE` against an
unnamed ``VALUES`` expression, producing a syntax that allows column-oriented
selection from a ``VALUES`` construct on modern versions of PostgreSQL, SQLite,
and MariaDB.

Fixes: #12734
Change-Id: I4a0146418420cce3cbbda4e50f5eb32206dc696b
2025-07-15 14:27:01 -04:00
Federico Caselli 0620473085 Improve handling of sentinel columns
Fixed issue in "insertmanyvalues" feature where an INSERT..RETURNING 
that also made use of a sentinel column to track results would fail to 
filter out the additional column when :meth:`.Result.unique` were used 
to uniquify the result set.
    
Fixes: #10802
Change-Id: Ie4f9dab96193099002088c5219cc41a543a00f62
2025-07-14 19:28:00 +00:00
Mike Bayer 89b81ec8c4 add CRUD column marker
Added new Core feature :func:`_sql.from_dml_column` that may be used in
expressions inside of :meth:`.UpdateBase.values` for INSERT or UPDATE; this
construct will copy whatever SQL expression is used for the given target
column in the statement to be used with additional columns. The construct
is mostly intended to be a helper with ORM :class:`.hybrid_property` within
DML hooks.

This is the Core side of the feature being added to the ORM
for #12496

Change-Id: Ic568638a8ce3607deea44af988b6451b30cde36c
2025-07-03 12:11:45 -04:00
Mike Bayer 637ecd40eb support insert of table columns in specific positions
Added method :meth:`.TableClause.insert_column` to complement
:meth:`.TableClause.append_column`, which inserts the given column at a
specific index.   This can be helpful for prepending primary key columns to
tables, etc.

Fixes: #7910
Change-Id: Ife1eb8ad90aa61d38c457a86312cfe5d0d471106
2025-07-02 17:22:40 -04:00
Mike Bayer dc0d081762 hardening against inappropriate multi-table updates
Hardening of the compiler's actions for UPDATE statements that access
multiple tables to report more specifically when tables or aliases are
referenced in the SET clause; on cases where the backend does not support
secondary tables in the SET clause, an explicit error is raised, and on the
MySQL or similar backends that support such a SET clause, more specific
checking for not-properly-included tables is performed.  Overall the change
is preventing these erroneous forms of UPDATE statements from being
compiled, whereas previously it was relied on the database to raise an
error, which was not always guaranteed to happen, or to be non-ambiguous,
due to cases where the parent table included the same column name as the
secondary table column being updated.

Fixed bug where the ORM would pull in the wrong column into an UPDATE when
a key name inside of the :meth:`.ValuesBase.values` method could be located
from an ORM entity mentioned in the statement, but where that ORM entity
was not the actual table that the statement was inserting or updating.  An
extra check for this edge case is added to avoid this problem.

Fixes: #12692
Change-Id: I342832b09dda7ed494caaad0cbb81b93fc10fe18
2025-06-24 10:19:48 -04:00
Mike Bayer c96805a43a rework wraps_column_expression logic to be purely compile time checking
Fixed issue where :func:`.select` of a free-standing, unnamed scalar expression that
has a unary operator applied, such as negation, would not apply result
processors to the selected column even though the correct type remains in
place for the unary expression.

This change opened up a typing rabbithole where we were led to also
improve and harden the typing for the Exists element, in particular
in that the Exists now always refers to a ScalarSelect object, and
no longer a SelectStatementGrouping within the _regroup() cases; there
did not seem to be any reason for this inconsistency.

Fixes: #12681
Change-Id: If9131807941030c627ab31ede4ccbd86e44e707f
2025-06-19 10:31:31 -04:00
Mike Bayer 239f629b9a update pickle tests
Since I want to get rid of util.portable_instancemethod, first
make sure we are testing pickle extensively including going through
all protocols for all metadata-oriented tests.

Change-Id: I0064bc16033939780e50c7a8a4ede60ef5835b38
2025-06-11 15:19:23 -04:00
Federico Caselli 084761c090 The `Enum.inherit_schema` now defaults to true
Changed the default value of :paramref:`_types.Enum.inherit_schema` to
``True`` when :paramref:`_types.Enum.schema` and
:paramref:`_types.Enum.metadata` parameters are not provided.
The same behavior has been applied also to PostgreSQL
:class:`_postgresql.DOMAIN` type.

Fixes: #10594
Change-Id: Id3d819e3608974353e365cd063d9c5e40a071e73
2025-05-27 16:06:49 -04:00
Aramís Segovia 8bd314378c Support matmul (@) as an optional operator.
Allow custom operator systems to use the @ Python operator (#12479).

### Description
Add a dummy implementation for the  `__matmul__` operator rasing `NotImplementedError` by default.

### Checklist
<!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once)

-->

This pull request is:

- [ ] A documentation / typographical / small typing error fix
	- Good to go, no issue or tests are needed
- [ ] A short code fix
	- please include the issue number, and create an issue if none exists, which
	  must include a complete example of the issue.  one line code fixes without an
	  issue and demonstration will not be accepted.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.   one line code fixes without tests will not be accepted.
- [X] A new feature implementation
	- please include the issue number, and create an issue if none exists, which must
	  include a complete example of how the feature would look.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.

**Have a nice day!**

Closes: #12583
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12583
Pull-request-sha: 7e69d23610

Change-Id: Ia0d565decd437b940efd3b97478c16d7a0377bc6
2025-05-13 16:18:11 -04:00
Justine Krejcha b4d7bf7a2f typing: pg: type NamedType create/drops (fixes #12557)
Type the `create` and `drop` functions for `NamedType`s

Also partially type the SchemaType create/drop functions more generally

One change to this is that the default parameter of `None` is removed. It doesn't work and will fail with a `AttributeError` at runtime since it immediately tries to access a property of `None` which doesn't exist.

Fixes #12557

This pull request is:

- [X] A documentation / typographical / small typing error fix
	- Good to go, no issue or tests are needed
- [X] A short code fix
	- please include the issue number, and create an issue if none exists, which
	  must include a complete example of the issue.  one line code fixes without an
	  issue and demonstration will not be accepted.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.   one line code fixes without tests will not be accepted.
- [ ] A new feature implementation
	- please include the issue number, and create an issue if none exists, which must
	  include a complete example of how the feature would look.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.

**Have a nice day!**

Closes: #12558
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12558
Pull-request-sha: 75c8d81bfb

Change-Id: I173771d365f34f54ab474b9661e1cdc70cc4de84
2025-05-07 21:40:18 -04:00
suraj 1b780ce3d3 Added vector datatype support in Oracle dialect
Added new datatype :class:`_oracle.VECTOR` and accompanying DDL and DQL
support to fully support this type for Oracle Database. This change
includes the base :class:`_oracle.VECTOR` type that adds new type-specific
methods ``l2_distance``, ``cosine_distance``, ``inner_product`` as well as
new parameters ``oracle_vector`` for the :class:`.Index` construct,
allowing vector indexes to be configured, and ``oracle_fetch_approximate``
for the :meth:`.Select.fetch` clause.  Pull request courtesy Suraj Shaw.

Fixes: #12317
Closes: #12321
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12321
Pull-request-sha: a72a18a45c

Change-Id: I6f3af4623ce439d0820c14582cd129df293f0ba8
2025-05-05 11:43:30 -04:00