summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
Commit message (Collapse)AuthorAgeFilesLines
* use ..deprecated directive w/ version in all casesMike Bayer2019-01-117-92/+160
| | | | | | | | | These changes should be ported from 1.3 back to 1.0 or possibly 0.9 to the extent they are relevant in each version. In 1.3 we hope to turn all deprecation documentation into warnings. Change-Id: I205186cde161af9389af513a425c62ce90dd54d8
* Post black reformattingMike Bayer2019-01-0619-526/+557
| | | | | | | | | | | | | Applied on top of a pure run of black -l 79 in I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9, this set of changes resolves all remaining flake8 conditions for those codes we have enabled in setup.cfg. Included are resolutions for all remaining flake8 issues including shadowed builtins, long lines, import order, unused imports, duplicate imports, and docstring issues. Change-Id: I4f72d3ba1380dd601610ff80b8fb06a2aff8b0fe
* Run black -l 79 against all source filesMike Bayer2019-01-0619-3129/+4603
| | | | | | | | | | | | | | This is a straight reformat run using black as is, with no edits applied at all. The black run will format code consistently, however in some cases that are prevalent in SQLAlchemy code it produces too-long lines. The too-long lines will be resolved in the following commit that will resolve all remaining flake8 issues including shadowed builtins, long lines, import order, unused imports, duplicate imports, and docstring issues. Change-Id: I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9
* commit 1b774808c926665047bf353222ecd191679a95d1Lele Gaifax2018-12-301-4/+4
| | | | | | | | | | | | | | | Author: Lele Gaifax <lele@metapensiero.it> Date: Tue Dec 25 12:35:41 2018 +0100 Consistently use "PostgreSQL", fixing also a few doc glitches commit 0e382aaee4427193926f0dc10ad29056bc12c85e Author: Lele Gaifax <lele@metapensiero.it> Date: Tue Dec 25 12:08:49 2018 +0100 Remove duplicated words Change-Id: Iaa586b9412f46a50fe6ff3bbb92e07d6cb1905c8
* Rewrite the convert_unicode docs and add tons of dragonsMike Bayer2018-12-211-22/+36
| | | | | | | These flags will all be going away as Python 3 has solved all of this. Change-Id: I4f581d8dd7826dd823b671d0d8e72250284236c8
* Removed the leading underscore for visitor_iterator propertyAgam Rafaeli2018-12-051-4/+4
| | | | | | | | A leading underscore usually denotes a private member. Since this is a property and it is used in Query I removed the leading underscore Change-Id: I8a35c09fd6d20ee0a13568ed7257a08b7bee2a08 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4398
* Merge "Allow optional *args with base AnsiFunction"mike bayer2018-11-302-10/+22
|\
| * Allow optional *args with base AnsiFunctionMike Bayer2018-11-292-10/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | Amended the :class:`.AnsiFunction` class, the base of common SQL functions like ``CURRENT_TIMESTAMP``, to accept positional arguments like a regular ad-hoc function. This to suit the case that many of these functions on specific backends accept arguments such as "fractional seconds" precision and such. If the function is created with arguments, it renders the the parenthesis and the arguments. If no arguents are present, the compiler generates the non-parenthesized form. Fixes: #4386 Change-Id: Ic492ef177e4987cec99ec4d95f55292be8daa087
* | typoRaphael2018-11-291-1/+1
|/ | | typo
* Merge "Allow join() to pick the best candidate from multiple froms/entities"mike bayer2018-11-152-2/+101
|\
| * Allow join() to pick the best candidate from multiple froms/entitiesMike Bayer2018-11-142-2/+101
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Refactored :meth:`.Query.join` to further clarify the individual components of structuring the join. This refactor adds the ability for :meth:`.Query.join` to determine the most appropriate "left" side of the join when there is more than one element in the FROM list or the query is against multiple entities. In particular this targets the regression we saw in :ticket:`4363` but is also of general use. The codepaths within :meth:`.Query.join` are now easier to follow and the error cases are decided more specifically at an earlier point in the operation. Fixes: #4365 Change-Id: I403f451243904a020ceab4c3f94bead550c7b2d5
* | Merge "Add Sequence to StrSQLCompiler"mike bayer2018-11-131-0/+3
|\ \ | |/ |/|
| * Add Sequence to StrSQLCompilerMike Bayer2018-11-101-0/+3
| | | | | | | | | | | | | | | | | | | | Added :class:`.Sequence` to the "string SQL" system that will render a meaningful string expression (``"<next sequence value: my_sequence>"``) when stringifying without a dialect a statement that includes a "sequence nextvalue" expression, rather than raising a compilation error. Fixes: #4144 Change-Id: Ia910f0e22008a7cde7597365954ede324101cf4d
* | Merge "Add new "all columns" naming convention tokens"mike bayer2018-11-113-37/+85
|\ \ | |/ |/|
| * Add new "all columns" naming convention tokensMike Bayer2018-11-103-37/+85
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Added new naming convention tokens ``column_0N_name``, ``column_0_N_name``, etc., which will render the names / keys / labels for all columns referenced by a particular constraint in a sequence. In order to accommodate for the length of such a naming convention, the SQL compiler's auto-truncation feature now applies itself to constraint names as well, which creates a shortened, deterministically generated name for the constraint that will apply to a target backend without going over the character limit of that backend. Additional notes: 1. the SQLite dialect had a format_index method that was apparently not used, removed. 2. the naming convention logic has been applying the foreign key remote column spec to the naming convention, and not the actual column name. In the case where the referenced Table object uses .key inside the columns and these are what ForeignKey() references, the naming convention was doing the wrong thing. The patch here fixes this, however this isn't noted in the migration notes. Fixes: #3989 Change-Id: Ib24f4754b886676096c480fc54b2e5c2463ac99a
* | Implement SQLite ON CONFLICT for constraintsDenis Kataev2018-11-071-6/+7
|/ | | | | | | | | | | Implemented the SQLite ``ON CONFLICT`` clause as understood at the DDL level, e.g. for primary key, unique, and CHECK constraints as well as specified on a :class:`.Column` to satisfy inline primary key and NOT NULL. Pull request courtesy Denis Kataev. Fixes: #4360 Change-Id: I4cd4bafa8fca41e3101c87dbbfe169741bbda3f4 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/431
* Add missing spacewodim2018-10-301-1/+1
|
* Support tuples of heterogeneous types for empty expanding INMike Bayer2018-10-033-2/+21
| | | | | | | | | Pass a list of all the types for the left side of an IN expression to the visit_empty_set_expr() method, so that the "empty expanding IN" can produce clauses for each element. Fixes: #4271 Change-Id: I2738b9df2292ac01afda37f16d4fa56ae7bf9147
* Merge "Import from collections.abc"mike bayer2018-09-272-4/+3
|\
| * Import from collections.abcxtreak2018-09-272-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed additional warnings generated by Python 3.7 due to changes in the organization of the Python ``collections`` and ``collections.abc`` packages. Previous ``collections`` warnings were fixed in version 1.2.11. Pull request courtesy xtreak. See I2d1c0ef97c8ecac7af152cc56263422a40faa6bb for the original collections.abc fixes. Fixes: #4339 Change-Id: Ia92d2461f20309fb33ea6c6f592f7d4e7e32ae7a Pull-request: https://github.com/zzzeek/sqlalchemy/pull/475
* | Copy create_constraint flag for EnumMike Bayer2018-09-251-1/+1
|/ | | | | | | | | Fixed bug where the :paramref:`.Enum.create_constraint` flag on the :class:`.Enum` datatype would not be propagated to copies of the type, which affects use cases such as declarative mixins and abstract bases. Fixes: #4341 Change-Id: I978be65f33a616fe4d5f5de03fb3eaab6f6a2272
* Allow dialects to customize group by clause compilationSamuel Chou2018-09-201-9/+13
| | | | | | | | | | | Refactored :class:`.SQLCompiler` to expose a :meth:`.SQLCompiler.group_by_clause` method similar to the :meth:`.SQLCompiler.order_by_clause` and :meth:`.SQLCompiler.limit_clause` methods, which can be overridden by dialects to customize how GROUP BY renders. Pull request courtesy Samuel Chou. Change-Id: I0a7238e55032558c27a0c56a72907c7b883456f1 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/474
* Adapt right side in join if lateral detectedMike Bayer2018-09-181-1/+3
| | | | | | | | | | | Fixed bug where use of :class:`.Lateral` construct in conjunction with :meth:`.Query.join` as well as :meth:`.Query.select_entity_from` would not apply clause adaption to the right side of the join. "lateral" introduces the use case of the right side of a join being correlatable. Previously, adaptation of this clause wasn't considered. Fixes: #4334 Change-Id: I3631e562092769d30069a2aa5e50a580f4661a23
* document expanding bound parameters, in_(), and baked query use casesMike Bayer2018-08-272-12/+82
| | | | Change-Id: I09ccd73ebabbea4b5098ba5b170786ac065444c8
* Correct expanding docs to support empty listsMike Bayer2018-08-271-4/+5
| | | | Change-Id: I9375b2055602216f9f25d32b2f7c035ae4280bd0
* Pass desired array type from pg.array_agg to functions.array_aggMike Bayer2018-08-221-1/+2
| | | | | | | | | | | Fixed the :func:`.postgresql.array_agg` function, which is a slightly altered version of the usual :func:`.functions.array_agg` function, to also accept an incoming "type" argument without forcing an ARRAY around it, essentially the same thing that was fixed for the generic function in 1.1 in :ticket:`4107`. Fixes: #4324 Change-Id: I399a29f59c945a217cdd22c65ff0325edea8ea65
* Add missing range_ / rows parameters to additional over() methodsMike Bayer2018-08-191-4/+8
| | | | | | | | | | | | Added missing window function parameters :paramref:`.WithinGroup.over.range_` and :paramref:`.WithinGroup.over.rows` parameters to the :meth:`.WithinGroup.over` and :meth:`.FunctionFilter.over` methods, to correspond to the range/rows feature added to the "over" method of SQL functions as part of :ticket:`3049` in version 1.1. Fixes: #4322 Change-Id: I77dcdac65c699a4b52a3fc3ee09a100ffb4fc20e
* Add concept of "implicit boolean", treat as nativeMike Bayer2018-08-154-2/+32
| | | | | | | | | | | | | | | Fixed issue that is closely related to :ticket:`3639` where an expression rendered in a boolean context on a non-native boolean backend would be compared to 1/0 even though it is already an implcitly boolean expression, when :meth:`.ColumnElement.self_group` were used. While this does not affect the user-friendly backends (MySQL, SQLite) it was not handled by Oracle (and possibly SQL Server). Whether or not the expression is implicitly boolean on any database is now determined up front as an additional check to not generate the integer comparison within the compliation of the statement. Fixes: #4320 Change-Id: Iae0a65e5c01bd576e64733c3651e1e1a1a1b240c
* Fixed issue with :meth:`.TypeEngine.bind_expression` andMike Bayer2018-08-082-9/+43
| | | | | | | | | | | | :meth:`.TypeEngine.column_expression` methods where these methods would not work if the target type were part of a :class:`.Variant`, or other target type of a :class:`.TypeDecorator`. Additionally, the SQL compiler now calls upon the dialect-level implementation when it renders these methods so that dialects can now provide for SQL-level processing for built-in types. Change-Id: Ic7b39575184db582e628e6ecee48dcda7d03a817 Fixes: #3981
* Add support of empty list in exanding of bindparamNicolas Rolin2018-08-071-0/+6
| | | | | | | | | | | Added new logic to the "expanding IN" bound parameter feature whereby if the given list is empty, a special "empty set" expression that is specific to different backends is generated, thus allowing IN expressions to be fully dynamic including empty IN expressions. Fixes: #4271 Change-Id: Icc3c73bbd6005206b9d06baaeb14a097af5edd36 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/432
* Include UPDATE/DELETE extra_froms in correlationMike Bayer2018-08-041-12/+15
| | | | | | | | | | | | | | | | | Fixed bug where the multi-table support for UPDATE and DELETE statements did not consider the additional FROM elements as targets for correlation, when a correlated SELECT were also combined with the statement. This change now includes that a SELECT statement in the WHERE clause for such a statement will try to auto-correlate back to these additional tables in the parent UPDATE/DELETE or unconditionally correlate if :meth:`.Select.correlate` is used. Note that auto-correlation raises an error if the SELECT statement would have no FROM clauses as a result, which can now occur if the parent UPDATE/DELETE specifies the same tables in its additional set of tables ; specify :meth:`.Select.correlate` explicitly to resolve. Change-Id: Ie11eaad7e49af3f59df11691b104d6359341bdae Fixes: #4313
* Merge "Drop default-related structures after the Table is dropped."mike bayer2018-07-111-5/+11
|\
| * Drop default-related structures after the Table is dropped.Mike Bayer2018-07-101-5/+11
| | | | | | | | | | | | | | | | | | | | | | | | Fixed bug where a :class:`.Sequence` would be dropped explicitly before any :class:`.Table` that refers to it, which breaks in the case when the sequence is also involved in a server-side default for that table, when using :meth:`.MetaData.drop_all`. The step which processes sequences to be dropped via non server-side column default functions is now invoked after the table itself is dropped. Change-Id: I185f2cc76d2011ad4dd3ba9bde5d8aef0ec335ae Fixes: #4300
* | Merge "Add all "like", "between", "is" operators as comparison operators"mike bayer2018-07-101-7/+36
|\ \
| * | Add all "like", "between", "is" operators as comparison operatorsMike Bayer2018-07-101-7/+36
| |/ | | | | | | | | | | | | | | | | | | | | Added "like" based operators as "comparison" operators, including :meth:`.ColumnOperators.startswith` :meth:`.ColumnOperators.endswith` :meth:`.ColumnOperators.ilike` :meth:`.ColumnOperators.notilike` among many others, so that all of these operators can be the basis for an ORM "primaryjoin" condition. Change-Id: Idb13961f0c74462a139fc3444626e042f798ff08 Fixes: #4302
* | Sqlite jsonIlja Everilä2018-07-101-2/+7
|/ | | | | | | | | | | Added support for SQLite's json functionality via the new SQLite implementation for :class:`.sqltypes.JSON`, :class:`.sqlite.JSON`. The name used for the type is ``JSON``, following an example found at SQLite's own documentation. Pull request courtesy Ilja Everilä. Fixes: #3850 Change-Id: I3d2714fb8655343a99d13dc751b16b93d05d7dda Pull-request: https://github.com/zzzeek/sqlalchemy/pull/434
* support functions "as binary comparison"Mike Bayer2018-07-093-2/+114
| | | | | | | | | Added new feature :meth:`.FunctionElement.as_comparison` which allows a SQL function to act as a binary comparison operation that can work within the ORM. Change-Id: I07018e2065d09775c0406cabdd35fc38cc0da699 Fixes: #3831
* Merge "Support JOIN in UPDATE..FROM"mike bayer2018-06-251-4/+13
|\
| * Support JOIN in UPDATE..FROMMike Bayer2018-06-131-4/+13
| | | | | | | | | | | | | | | | | | | | The :class:`.Update` construct now accommodates a :class:`.Join` object as supported by MySQL for UPDATE..FROM. As the construct already accepted an alias object for a similar purpose, the feature of UPDATE against a non-table was already implied so this has been added. Change-Id: I7b2bca627849384d5377abb0c94626463e4fad04 Fixes: #3645
* | Merge "render WITH clause after INSERT for INSERT..SELECT on Oracle, MySQL"mike bayer2018-06-241-2/+7
|\ \
| * | render WITH clause after INSERT for INSERT..SELECT on Oracle, MySQLMike Bayer2018-06-181-2/+7
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed INSERT FROM SELECT with CTEs for the Oracle and MySQL dialects, where the CTE was being placed above the entire statement as is typical with other databases, however Oracle and MariaDB 10.2 wants the CTE underneath the "INSERT" segment. Note that the Oracle and MySQL dialects don't yet work when a CTE is applied to a subquery inside of an UPDATE or DELETE statement, as the CTE is still applied to the top rather than inside the subquery. Also adds test suite support CTEs against backends. Change-Id: I8ac337104d5c546dd4f0cd305632ffb56ac8bf90 Fixes: #4275 Fixes: #4230
* | Lookup index columns in parent table by key for copyMike Bayer2018-06-141-1/+2
|/ | | | | | | | | | | | | Fixed regression in 1.2 due to :ticket:`4147` where a :class:`.Table` that has had some of its indexed columns redefined with new ones, as would occur when overriding columns during reflection or when using :paramref:`.Table.extend_existing`, such that the :meth:`.Table.tometadata` method would fail when attempting to copy those indexes as they still referred to the replaced column. The copy logic now accommodates for this condition. Change-Id: I521aa2c9f3baa0e84598bbdd6ffe4bf07b6e3ba8 Fixes: #4279
* Turn oracle BINARY_DOUBLE, BINARY_FLOAT, DOUBLE_PRECISION into floatsMike Bayer2018-05-251-1/+29
| | | | | | | | | | | | | | | | | The Oracle BINARY_FLOAT and BINARY_DOUBLE datatypes now participate within cx_Oracle.setinputsizes(), passing along NATIVE_FLOAT, so as to support the NaN value. Additionally, :class:`.oracle.BINARY_FLOAT`, :class:`.oracle.BINARY_DOUBLE` and :class:`.oracle.DOUBLE_PRECISION` now subclass :class:`.Float`, since these are floating point datatypes, not decimal. These datatypes were already defaulting the :paramref:`.Float.asdecimal` flag to False in line with what :class:`.Float` already does. Added reflection capabilities for the :class:`.oracle.BINARY_FLOAT`, :class:`.oracle.BINARY_DOUBLE` datatypes. Change-Id: Id99b912e83052654a17d07dc92b4dcb958cb7600 Fixes: #4264
* Fix string formatting TypeError if tuple is passedMiguel Ventura2018-05-171-1/+1
| | | | | | | | | | Fixed issue where the "ambiguous literal" error message used when interpreting literal values as SQL expression values would encounter a tuple value, and fail to format the message properly. Pull request courtesy Miguel Ventura. Change-Id: I50d5d32d5f80ec79703a42d4b19b42c2f9701f24 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/442
* SQL Server is not native boolean; add new flag for CHECK constraintMike Bayer2018-05-101-1/+2
| | | | | | | | | | | | | | Fixed a 1.2 regression caused by :ticket:`4061` where the SQL Server "BIT" type would be considered to be "native boolean". The goal here was to avoid creating a CHECK constraint on the column, however the bigger issue is that the BIT value does not behave like a true/false constant and cannot be interpreted as a standalone expression, e.g. "WHERE <column>". The SQL Server dialect now goes back to being non-native boolean, but with an extra flag that still avoids creating the CHECK constraint. Change-Id: I4765d2a2a00b0d14f50282603cc4d48d4739dac1 Fixes: #4250
* Raise informative exception for non-sortable PKMike Bayer2018-04-091-1/+0
| | | | | | | | | | | An informative exception is re-raised when a primary key value is not sortable in Python during an ORM flush under Python 3, such as an ``Enum`` that has no ``__lt__()`` method; normally Python 3 raises a ``TypeError`` in this case. The flush process sorts persistent objects by primary key in Python so the values must be sortable. Change-Id: Ia186968982dcd1234b82f2e701fefa2a1668a7e4 Fixes: #4232
* Ensure all visit_sequence accepts **kw argsMike Bayer2018-04-041-1/+1
| | | | | | | | | | Fixed issue where the compilation of an INSERT statement with the "literal_binds" option that also uses an explicit sequence and "inline" generation, as on Postgresql and Oracle, would fail to accommodate the extra keyword argument within the sequence processing routine. Change-Id: Ibdab7d340aea7429a210c9535ccf1a3e85f074fb Fixes: #4231
* Track if we're rendering within the CTE recursivelyMike Bayer2018-03-141-1/+9
| | | | | | | | | | Fixed a regression that occurred from the previous fix to :ticket:`4204` in version 1.2.5, where a CTE that refers to itself after the :meth:`.CTE.alias` method has been called would not refer to iself correctly. Change-Id: Iaa63d65ad2b90c8693f9953fbb32dbb10c73a037 Fixes: #4204
* Clone _cte_alias instead of assigning "self"Mike Bayer2018-03-051-1/+1
| | | | | | | | | | Fixed bug in :class:.`CTE` construct along the same lines as that of :ticket:`4204` where a :class:`.CTE` that was aliased would not copy itself correctly during a "clone" operation as is frequent within the ORM as well as when using the :meth:`.ClauseElement.params` method. Change-Id: Id68d72dd244dedfc7bd6116c9a5123c51a55ea20 Fixes: #4210
* Check existing CTE for an alias name when rendering FROM clauseMike Bayer2018-03-011-50/+56
| | | | | | | | | | Fixed bug in CTE rendering where a :class:`.CTE` that was also turned into an :class:`.Alias` would not render its "ctename AS aliasname" clause appropriately if there were more than one reference to the CTE in a FROM clause. Change-Id: If8cff27a2f4faa5eceb59aa86398db6edb3b9e72 Fixes: #4204