summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
Commit message (Collapse)AuthorAgeFilesLines
* remove theme altogethersphinx_mini_buildMike Bayer2023-04-231-12/+0
| | | | Change-Id: Iaa5d1ac26007451c09d6982c06d8ad6ed22d30bc
* remove all labels and links that are no longer locatableMike Bayer2023-04-238-28/+28
| | | | Change-Id: Ic975b8c20bc297d3a04dde0bed143783ae951cd4
* support slice access for .cMike Bayer2023-04-221-5/+17
| | | | | | | | | | | | Added support for slice access with :class:`.ColumnCollection`, e.g. ``table.c[0:5]``, ``subquery.c[:-1]`` etc. Slice access returns a sub :class:`.ColumnCollection` in the same way as passing a tuple of keys. This is a natural continuation of the key-tuple access added for :ticket:`8285`, which it appears to be an oversight that this usage was omitted. Change-Id: I6378642f39501ffbbae4acadf1dc38a43c39d722 References: #8285 References: #9690
* Merge "add deterministic imv returning ordering using sentinel columns" into ↵mike bayer2023-04-219-115/+1133
|\ | | | | | | main
| * add deterministic imv returning ordering using sentinel columnsMike Bayer2023-04-219-115/+1133
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Repaired a major shortcoming which was identified in the :ref:`engine_insertmanyvalues` performance optimization feature first introduced in the 2.0 series. This was a continuation of the change in 2.0.9 which disabled the SQL Server version of the feature due to a reliance in the ORM on apparent row ordering that is not guaranteed to take place. The fix applies new logic to all "insertmanyvalues" operations, which takes effect when a new parameter :paramref:`_dml.Insert.returning.sort_by_parameter_order` on the :meth:`_dml.Insert.returning` or :meth:`_dml.UpdateBase.return_defaults` methods, that through a combination of alternate SQL forms, direct correspondence of client side parameters, and in some cases downgrading to running row-at-a-time, will apply sorting to each batch of returned rows using correspondence to primary key or other unique values in each row which can be correlated to the input data. Performance impact is expected to be minimal as nearly all common primary key scenarios are suitable for parameter-ordered batching to be achieved for all backends other than SQLite, while "row-at-a-time" mode operates with a bare minimum of Python overhead compared to the very heavyweight approaches used in the 1.x series. For SQLite, there is no difference in performance when "row-at-a-time" mode is used. It's anticipated that with an efficient "row-at-a-time" INSERT with RETURNING batching capability, the "insertmanyvalues" feature can be later be more easily generalized to third party backends that include RETURNING support but not necessarily easy ways to guarantee a correspondence with parameter order. Fixes: #9618 References: #9603 Change-Id: I1d79353f5f19638f752936ba1c35e4dc235a8b7c
* | Define type hints for remaining column operatorsMartijn Pieters2023-04-181-0/+43
|/ | | | | | | | | | | | | | | | | | Added typing information for recently added operators :meth:`.ColumnOperators.icontains`, :meth:`.ColumnOperators.istartswith`, :meth:`.ColumnOperators.iendswith`, and bitwise operators :meth:`.ColumnOperators.bitwise_and`, :meth:`.ColumnOperators.bitwise_or`, :meth:`.ColumnOperators.bitwise_xor`, :meth:`.ColumnOperators.bitwise_not`, :meth:`.ColumnOperators.bitwise_lshift` :meth:`.ColumnOperators.bitwise_rshift`. Pull request courtesy Martijn Pieters. Fixes: #9650 Closes: #9652 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9652 Pull-request-sha: 005c56848af8cff6bb19f71541873027f141eb6e Change-Id: I2fa06eb42ce668df9d9c760d233906f87484dd12
* Add additional seealso to schema reflect parametersFederico Caselli2023-04-131-0/+19
| | | | | References: #9606 Change-Id: I1213f881621a80eb78a2db84e53150437144f26c
* Merge "Remove old versionadded and versionchanged" into mainmike bayer2023-04-1213-300/+1
|\
| * Remove old versionadded and versionchangedFederico Caselli2023-04-1213-300/+1
| | | | | | | | | | | | | | Removed versionadded and versionchanged for version prior to 1.2 since they are no longer useful. Change-Id: I5c53d1188bc5fec3ab4be39ef761650ed8fa6d3e
* | establish column_property and query_expression as readonly from a dc perspectiveMike Bayer2023-04-121-0/+3
|/ | | | | | | | | | | | | | | | | | | | | | | | | | Fixed bug in ORM Declarative Dataclasses where the :func:`_orm.queryable_attribute` and :func:`_orm.column_property` constructs, which are documented as read-only constructs in the context of a Declarative mapping, could not be used with a :class:`_orm.MappedAsDataclass` class without adding ``init=False``, which in the case of :func:`_orm.queryable_attribute` was not possible as no ``init`` parameter was included. These constructs have been modified from a dataclass perspective to be assumed to be "read only", setting ``init=False`` by default and no longer including them in the pep-681 constructor. The dataclass parameters for :func:`_orm.column_property` ``init``, ``default``, ``default_factory``, ``kw_only`` are now deprecated; these fields don't apply to :func:`_orm.column_property` as used in a Declarative dataclasses configuration where the construct would be read-only. Also added read-specific parameter :paramref:`_orm.queryable_attribute.compare` to :func:`_orm.queryable_attribute`; :paramref:`_orm.queryable_attribute.repr` was already present. Added missing :paramref:`_orm.mapped_column.active_history` parameter to :func:`_orm.mapped_column` construct. Fixes: #9628 Change-Id: I2ab44d6b763b20410bd1ebb5ac949a6d223f1ce2
* optimize exec defaults a bitMike Bayer2023-04-091-1/+4
| | | | | | | since I am probably using this for the new "sentinel" thing, clean up this code, reduce codepaths and inline a bit Change-Id: I9cb312828e3bc23636f6db794b169f1acc4ebae3
* clarify the Uuid datatype handles Python uuid objects by defaultMike Bayer2023-03-311-0/+30
| | | | | Change-Id: I28147bfb4eb0762e9482d4f38bc1d89355152ad4 References: #9573
* Improve from_select typingFederico Caselli2023-03-271-4/+6
| | | | | | | | Properly type :paramref:`_dml.Insert.from_select.names` to accept a list of string or columns or mapped attributes. Fixes: #9514 Change-Id: I2a3396454e79bd2113fc3d57d1252a2e6d141310
* use clone, not constructor, in BindParameter.render_literal_execute()Mike Bayer2023-03-221-6/+3
| | | | | | | | | | | | | Fixed issue where the :meth:`_sql.BindParameter.render_literal_execute` method would fail when called on a parameter that also had ORM annotations associated with it. In practice, this would be observed as a failure of SQL compilation when using some combinations of a dialect that uses "FETCH FIRST" such as Oracle along with a :class:`_sql.Select` construct that uses :meth:`_sql.Select.limit`, within some ORM contexts, including if the statement were embedded within a relationship primaryjoin expression. Fixes: #9526 Change-Id: I2f512b6760a90293d274e60b06a891f10b276ecc
* implement content hashing for custom_op, not identityMike Bayer2023-03-182-3/+19
| | | | | | | | | Fixed critical SQL caching issue where use of the :meth:`_sql.Operators.op` custom operator function would not produce an appropriate cache key, leading to reduce the effectiveness of the SQL cache. Fixes: #9506 Change-Id: I3eab1ddb5e09a811ad717161a59df0884cdf70ed
* Document generic type parameters to FunctionElement and GenericFunction (#9079)Stephen Rosen2023-03-141-0/+18
| | | | | | | | | | | | | | | | * Document type parameters to FunctionElement Add a note to FunctionElement which indicates that the type is a typing.Generic class and points at GenericFunction examples for a specific example usage. A minimal reference is made to type checkers and IDEs as use-cases in order to try to contextualize this as an optional feature which supports particular use cases. Append to the GenericFunction examples a case which uses `DateTime` but also includes the generic type parameter (`datetime.datetime`). * Fix type annotated function usage example
* repair broken lambda patchMike Bayer2023-03-101-5/+10
| | | | | | | | | | | | | | | | in I4e0b627bfa187f1780dc68ec81b94db1c78f846a the 1.4 version has more changes than the main version, which failed to get the entire change, yet the whole thing was merged. Restore the missing mutex related code to the main version. Fixed regression where the fix for :ticket:`8098`, which was released in the 1.4 series and provided a layer of concurrency-safe checks for the lambda SQL API, included additional fixes in the patch that failed to be applied to the main branch. These additional fixes have been applied. Change-Id: Id172e09c421dafa6ef1d40b383aa4371de343864 References: #8098 Fixes: #9461
* Use independent TypeVar for ColumnElement.castMike Bayer2023-03-081-1/+1
| | | | | | | | | | Fixed typing issue where :meth:`.ColumnElement.cast` did not allow a :class:`.TypeEngine` argument independent of the type of the :class:`.ColumnElement` itself, which is the purpose of :meth:`.ColumnElement.cast`. Fixes: #9451 Change-Id: I68119c6a9e8bf896715eea79be2b4f36b1c141de
* resolve select to NULLTYPE if no columnsMike Bayer2023-03-072-0/+13
| | | | | | | | | | | | | | | | | Fixed regression where the :func:`_sql.select` construct would not be able to render if it were given no columns and then used in the context of an EXISTS, raising an internal exception instead. While an empty "SELECT" is not typically valid SQL, in the context of EXISTS databases such as PostgreSQL allow it, and in any case the condition now no longer raises an internal exception. For this case, also add an extra whitespace trim step for the unusual case that there are no columns to render. This is done in such a way as to not interfere with other test cases that are involving custom compilation schemes. Fixes: #9440 Change-Id: If65ba9ce15d371f09b4342ad0669143b7b082a78
* Merge "TextualSelect is ReturnsRowsRole" into mainmike bayer2023-03-043-14/+41
|\
| * TextualSelect is ReturnsRowsRoleMike Bayer2023-03-023-14/+41
| | | | | | | | | | | | | | | | | | | | Fixed typing bug where :meth:`_sql.Select.from_statement` would not accept :func:`_sql.text` or :class:`.TextualSelect` objects as a valid type. Additionally repaired the :class:`.TextClause.columns` method to have a return type, which was missing. Fixes: #9398 Change-Id: I627fc33bf83365e1c7f7c6ed29ea387dfd4a57d8
* | Merge "Add missing overload to Numeric" into mainmike bayer2023-03-042-7/+27
|\ \
| * | Add missing overload to NumericFederico Caselli2023-03-032-7/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Added missing init overload to :class:`_sql.Numeric` to allow type checkers to properly resolve the type var given the ``asdecimal`` parameter. this fortunately fixes a glitch in the generate_sql_functions script also Fixes: #9391 Change-Id: I9cecc40c52711489e9dbe663f110c3b81c7285e4
* | | Merge "Validate metadata schema arg" into mainmike bayer2023-03-041-0/+5
|\ \ \ | |_|/ |/| |
| * | Validate metadata schema argFederico Caselli2023-03-011-0/+5
| |/ | | | | | | | | | | | | Validate that when provided the :paramref:`_sql.MetaData.schema` argument of :class:`_sql.MetaData` is a string. Change-Id: I4237232d2ee0f5a4d0b9dbd9af5f5b57abf395b4
* | Restore export for nullslast/nullfirstFederico Caselli2023-02-281-0/+4
|/ | | | | | | | Previously only the snake case versions nulls_last/nulls_first were exported in the toplevel namespace. Fixes: #9390 Change-Id: I9088e858ae108a5c9106b9d8d82655ad605417cc
* use read-only Mapping for values dictionary typeMike Bayer2023-02-262-1/+6
| | | | | | | | | | Improved typing for the mapping passed to :meth:`.UpdateBase.values` to be more open-ended about collection type, by indicating read-only ``Mapping`` instead of writeable ``Dict``, the latter of which would error out under typing tools on too limited of a key type. Fixes: #9376 Change-Id: Ib7fdbba05ca7e1082409e1b5616e6a010262f032
* Allow custom sorting of column in the ORM.Federico Caselli2023-02-162-3/+6
| | | | | | | | | | | | | | | To accommodate a change in column ordering used by ORM Declarative in SQLAlchemy 2.0, a new parameter :paramref:`_orm.mapped_column.sort_order` has been added that can be used to control the order of the columns defined in the table by the ORM, for common use cases such as mixins with primary key columns that should appear first in tables. The change notes at :ref:`change_9297` illustrate the default change in ordering behavior (which is part of all SQLAlchemy 2.0 releases) as well as use of the :paramref:`_orm.mapped_column.sort_order` to control column ordering when using mixins and multiple classes (new in 2.0.4). Fixes: #9297 Change-Id: Ic7163d64efdc0eccb53d6ae0dd89ec83427fb675
* Merge "modernize hybrids and apply typing" into mainmike bayer2023-02-172-3/+5
|\
| * modernize hybrids and apply typingMike Bayer2023-02-162-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Improved the typing support for the :ref:`hybrids_toplevel` extension, updated all documentation to use ORM Annotated Declarative mappings, and added a new modifier called :attr:`.hybrid_property.inplace`. This modifier provides a way to alter the state of a :class:`.hybrid_property` **in place**, which is essentially what very early versions of hybrids did, before SQLAlchemy version 1.2.0 :ticket:`3912` changed this to remove in-place mutation. This in-place mutation is now restored on an **opt-in** basis to allow a single hybrid to have multiple methods set up, without the need to name all the methods the same and without the need to carefully "chain" differently-named methods in order to maintain the composition. Typing tools such as Mypy and Pyright do not allow same-named methods on a class, so with this change a succinct method of setting up hybrids with typing support is restored. Change-Id: Iea88025f023428f9f006846d09fbb4be391f5ebb References: #9321
* | Fix coercion issue for tuple bindparamsmike bayer2023-02-153-4/+30
|/ | | | | | | | | | | | Fixed issue where element types of a tuple value would be hardcoded to take on the types from a compared-to tuple, when the comparison were using the :meth:`.ColumnOperators.in_` operator. This was inconsistent with the usual way that types are determined for a binary expression, which is that the actual element type on the right side is considered first before applying the left-hand-side type. Fixes: #9313 Change-Id: Ia8874c09682a6512fcf4084cf14481024959c461
* Merge "Add ``Table.autoincrement_column``" into mainmike bayer2023-02-151-2/+24
|\
| * Add ``Table.autoincrement_column``Federico Caselli2023-02-141-2/+24
| | | | | | | | | | | | | | | | Added public property :attr:`_sql.Table.autoincrement_column` that returns the column identified as autoincrementing in the column. Fixes: #9277 Change-Id: If60d6f92e0df94f57d00ff6d89d285c61b02f5a4
* | completely lift-and-copy and_ / or_ documentationMike Bayer2023-02-131-0/+108
| | | | | | | | | | | | | | | | Sphinx refuses to write the correct docstring for these without placing a completely literal string with no interpolation of any kind. Current site has blank for these. Change-Id: Ie19a0b89d05b45509708585e6efca1a35f30adb5
* | Fix docs for `case` expression to match new syntax (#9279)Abdulhaq Emhemmed2023-02-101-4/+4
|/ | | | | | | | | * Fix docs for `case` expression to match new syntax Previously (before v1.4), the `whens` arg (when `value` is *not* used) used to be a list of conditions (a 2 item-tuple of condition + value). From v1.4, these are passed as positional args and the old syntax is not supported anymore. * Fix long lines
* generalize adapt_on_names to expect non-named elementsMike Bayer2023-02-101-3/+7
| | | | | | | | | | | | | | | | | | | | The fix in #9217 opened up adapt_on_names to more kinds of expressions than it was prepared for; adjust that logic and also refine in the ORM where we are using it, as we dont need it (yet) for the DML RETURNING use case. Fixed regression introduced in version 2.0.2 due to :ticket:`9217` where using DML RETURNING statements, as well as :meth:`_sql.Select.from_statement` constructs as was "fixed" in :ticket:`9217`, in conjunction with ORM mapped classes that used expressions such as with :func:`_orm.column_property`, would lead to an internal error within Core where it would attempt to match the expression by name. The fix repairs the Core issue, and also adjusts the fix in :ticket:`9217` to not take effect for the DML RETURNING use case, where it adds unnecessary overhead. Fixes: #9273 Change-Id: Ie0344efb12ff7df48f21e71e62dc598c76a6a0de
* apply self_group to all elements of multi-expressionMike Bayer2023-02-091-8/+9
| | | | | | | | | | | Fixed critical regression in SQL expression formulation in the 2.0 series due to :ticket:`7744` which improved support for SQL expressions that contained many elements against the same operator repeatedly; parenthesis grouping would be lost with expression elements beyond the first two elements. Fixes: #9271 Change-Id: Ib6ed5b71efe0f6816dab75bda622297fc89e3b49
* Remove `typing.Self` workaroundYurii Karabas2023-02-0811-387/+206
| | | | | | | | | | | | Remove ``typing.Self`` workaround, now using :pep:`673` for most methods that return ``Self``. Pull request courtesy Yurii Karabas. Fixes: #9254 Closes: #9255 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9255 Pull-request-sha: 2947df8ada79f5c3afe9c838e65993302199c2f7 Change-Id: Ic32015ad52e95a61f3913d43ea436aa9402804df
* Merge "Dedicated bitwise operators" into mainmike bayer2023-02-066-0/+176
|\
| * Dedicated bitwise operatorsjazzthief2023-02-066-0/+176
| | | | | | | | | | | | | | | | | | | | | | | | | | Added a full suite of new SQL bitwise operators, for performing database-side bitwise expressions on appropriate data values such as integers, bit-strings, and similar. Pull request courtesy Yegor Statkevich. Fixes: #8780 Closes: #9204 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9204 Pull-request-sha: a4541772a6a784f9161ad78ef84d2ea7a62fa8de Change-Id: I4c70e80f9548dcc1b4e3dccd71bd59d51d3ed46e
* | Use correct dialect annotationFederico Caselli2023-02-021-1/+1
|/ | | | | Fixes: #9222 Change-Id: Ife841a5cf5ec896405e84d8570ef63ce6176a5ec
* Merge "Add support for typing.Literal in Mapped" into mainmike bayer2023-02-011-11/+61
|\
| * Add support for typing.Literal in MappedFrederik Aalund2023-01-311-11/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Added support for :pep:`586` ``Literal`` to be used in the :paramref:`_orm.registry.type_annotation_map` as well as within :class:`.Mapped` constructs. To use custom types such as these, they must appear explicitly within the :paramref:`_orm.registry.type_annotation_map` to be mapped. Pull request courtesy Frederik Aalund. As part of this change, the support for :class:`.sqltypes.Enum` in the :paramref:`_orm.registry.type_annotation_map` has been expanded to include support for ``Literal[]`` types consisting of string values to be used, in addition to ``enum.Enum`` datatypes. If a ``Literal[]`` datatype is used within ``Mapped[]`` that is not linked in :paramref:`_orm.registry.type_annotation_map` to a specific datatype, a :class:`.sqltypes.Enum` will be used by default. Fixed issue involving the use of :class:`.sqltypes.Enum` within the :paramref:`_orm.registry.type_annotation_map` where the :paramref:`_sqltypes.Enum.native_enum` parameter would not be correctly copied to the mapped column datatype, if it were overridden as stated in the documentation to set this parameter to False. Fixes: #9187 Fixes: #9200 Closes: #9191 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9191 Pull-request-sha: 7d13f705307bf62560fc831f6f049a425d411374 Change-Id: Ife3ba2655f4897f806d6a9cf0041c69fd4f39e9d
* | Merge "Fixed typing of limit, offset and fetch to allow ``None``." into mainFederico Caselli2023-01-313-12/+13
|\ \ | |/ |/|
| * Fixed typing of limit, offset and fetch to allow ``None``.Federico Caselli2023-01-313-12/+13
| | | | | | | | | | Fixes: #9183 Change-Id: I1ac3e3698034826122ea8a0cdc9f8f55a10ed6c1
* | support NewType in type_annotation_mapMike Bayer2023-01-312-8/+11
|/ | | | | | | | | | | | | | | | | Added support for :pep:`484` ``NewType`` to be used in the :paramref:`_orm.registry.type_annotation_map` as well as within :class:`.Mapped` constructs. These types will behave in the same way as custom subclasses of types right now; they must appear explicitly within the :paramref:`_orm.registry.type_annotation_map` to be mapped. Within this change, the lookup between decl_api._resolve_type and TypeEngine._resolve_for_python_type is streamlined to not inspect the given type multiple times, instead passing in from decl_api to TypeEngine the already "flattened" version of a Generic or NewType type. Fixes: #9175 Change-Id: I227cf84b4b88e4567fa2d1d7da0c05b54e00c562
* Merge "don't count / gather INSERT bind names inside of a CTE" into mainmike bayer2023-01-302-43/+105
|\
| * don't count / gather INSERT bind names inside of a CTEMike Bayer2023-01-302-43/+105
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed regression related to the implementation for the new "insertmanyvalues" feature where an internal ``TypeError`` would occur in arrangements where a :func:`_sql.insert` would be referred towards inside of another :func:`_sql.insert` via a CTE; made additional repairs for this use case for positional dialects such as asyncpg when using "insertmanyvalues". at the core here is a change to positional insertmanyvalues where we now get exactly the positions for the "manyvalues" within the larger list, allowing non-"manyvalues" on the left and right sides at the same time, not assuming anything about how RETURNING renders etc., since CTEs are in the mix also. Fixes: #9173 Change-Id: I5ff071fbef0d92a2d6046b9c4e609bb008438afd
* | fix post-production typo for #9174Mike Bayer2023-01-301-1/+1
| | | | | | | | | | | | | | | | merged in cae662a6383d3ae8f3673c70c3118ea3a1a1606e with one typo fix afterwards Fixes: #9174 Change-Id: I5a525da8a95f40c75da627fed49ce828bd498248
* | Revert "fix post-production typo for #9174"Mike Bayer2023-01-301-1/+1
| | | | | | | | | | | | This reverts commit 3b60c3f53eab8ee5896b3fde525bcf31d4233658. some scratch code for isolation levels got pushed :(