summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/functions.py
Commit message (Collapse)AuthorAgeFilesLines
* Try to measure new style caching in the ORM, take twoMike Bayer2020-04-011-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Supercedes: If78fbb557c6f2cae637799c3fec2cbc5ac248aaf Trying to see if by making the cache key memoized, we still can have the older "identity" form of caching which is the cheapest of all, at the same time as the newer "cache key each time" version that is not nearly as cheap; but still much cheaper than no caching at all. Also needed is a per-execution update of _keymap when we invoke from a cached select, so that Column objects that are anonymous or otherwise adapted will match up. this is analogous to the adaption of bound parameters from the cache key. Adds test coverage for the keymap / construct_params() changes related to caching. Also hones performance to a large extent for statement construction and cache key generation. Also includes a new memoized attribute approach that vastly simplifies the previous approach of "group_expirable_memoized_property" and finally integrates cleanly with _clone(), _generate(), etc. no more hardcoding of attributes is needed, as well as that most _reset_memoization() calls are no longer needed as the reset is inherent in a _generate() call; this also has dramatic performance improvements. Change-Id: I95c560ffcbfa30b26644999412fb6a385125f663
* Correct ambiguous func / class linksMike Bayer2020-03-251-1/+1
| | | | | | | | | :func:`.sql.expression.select`, :func:`.sql.expression.insert` and :class:`.sql.expression.Insert` were hitting many ambiguous symbol errors, due to future.select, as well as the PG/MySQL variants of Insert. Change-Id: Iac862bfc172a7f7f0cbba5353a83dc203bed376c
* Remove print statement in favor of print() function in docs and examplesAlbert Tugushev2020-02-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | <!-- Provide a general summary of your proposed changes in the Title field above --> ### Description <!-- Describe your changes in detail --> Remove print statements ### 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: - [X] A documentation / typographical 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. - [ ] 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: #5166 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5166 Pull-request-sha: 04a7394f71298322188f0861b4dfe93e5485839d Change-Id: Ib90a59fac929661a18748c6e44966fb87e3978c6
* Create initial future package, RemovedIn20WarningMike Bayer2020-02-121-1/+1
| | | | | | | | | | | | | | | | | Reorganization of Select() is the first major element of the 2.0 restructuring. In order to start this we need to first create the new Select constructor and apply legacy elements to the old one. This in turn necessitates starting up the RemovedIn20Warning concept which itself need to refer to "sqlalchemy.future", so begin to establish this basic framework. Additionally, update the DML constructors with the newer no-keyword style. Remove the use of the "pending deprecation" and fix Query.add_column() deprecation which was not acting as deprecated. Fixes: #4845 Fixes: #4648 Change-Id: I0c7a22b2841a985e1c379a0bb6c94089aae6264c
* Support GenericFunction.name passed as a quoted_nameMike Bayer2020-01-061-3/+27
| | | | | | | | | | | | | | | A function created using :class:`.GenericFunction` can now specify that the name of the function should be rendered with or without quotes by assigning the :class:`.quoted_name` construct to the .name element of the object. Prior to 1.3.4, quoting was never applied to function names, and some quoting was introduced in :ticket:`4467` but no means to force quoting for a mixed case name was available. Additionally, the :class:`.quoted_name` construct when used as the name will properly register its lowercase name in the function registry so that the name continues to be available via the ``func.`` registry. Fixes: #5079 Change-Id: I0653ab8b16e75e628ce82dbbc3d0f77f8336c407
* happy new yearMike Bayer2020-01-011-1/+1
| | | | Change-Id: I08440dc25e40ea1ccea1778f6ee9e28a00808235
* Traversal and clause generation performance improvementsMike Bayer2019-12-141-0/+3
| | | | | | | Added one traversal test, callcounts have been brought from 29754 to 5173 so far. Change-Id: I164e9831600709ee214c1379bb215fdad73b39aa
* Add anonymizing context to cache keys, comparison; convert traversalMike Bayer2019-11-041-45/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Created new visitor system called "internal traversal" that applies a data driven approach to the concept of a class that defines its own traversal steps, in contrast to the existing style of traversal now known as "external traversal" where the visitor class defines the traversal, i.e. the SQLCompiler. The internal traversal system now implements get_children(), _copy_internals(), compare() and _cache_key() for most Core elements. Core elements with special needs like Select still implement some of these methods directly however most of these methods are no longer explicitly implemented. The data-driven system is also applied to ORM elements that take part in SQL expressions so that these objects, like mappers, aliasedclass, query options, etc. can all participate in the cache key process. Still not considered is that this approach to defining traversibility will be used to create some kind of generic introspection system that works across Core / ORM. It's also not clear if real statement caching using the _cache_key() method is feasible, if it is shown that running _cache_key() is nearly as expensive as compiling in any case. Because it is data driven, it is more straightforward to optimize using inlined code, as is the case now, as well as potentially using C code to speed it up. In addition, the caching sytem now accommodates for anonymous name labels, which is essential so that constructs which have anonymous labels can be cacheable, that is, their position within a statement in relation to other anonymous names causes them to generate an integer counter relative to that construct which will be the same every time. Gathering of bound parameters from any cache key generation is also now required as there is no use case for a cache key that does not extract bound parameter values. Applies-to: #4639 Change-Id: I0660584def8627cad566719ee98d3be045db4b8d
* Fix test failures from func doc fixMike Bayer2019-10-171-1/+1
| | | | | | | The doc edits in e45878bf4f9cdfb714dce8b2a4d705178947674d triggered a doctest and a pep8 failure. Change-Id: I41c6cba9bab2d3721d9c6280be47eec32f4b4736
* fix func docsMike Bayer2019-10-171-69/+108
| | | | | | | | sphinx is not generating the docs for func. cross-copy __doc__ and also add more links. Fixes: #4922 Change-Id: I5512111d726b6fcf9821be730c9e29adc73c95cb
* Allow duplicate columns in from clauses and selectablesMike Bayer2019-07-111-1/+2
| | | | | | | | | | | | | | | | | | The :func:`.select` construct and related constructs now allow for duplication of column labels and columns themselves in the columns clause, mirroring exactly how column expressions were passed in. This allows the tuples returned by an executed result to match what was SELECTed for in the first place, which is how the ORM :class:`.Query` works, so this establishes better cross-compatibility between the two constructs. Additionally, it allows column-positioning-sensitive structures such as UNIONs (i.e. :class:`.CompoundSelect`) to be more intuitively constructed in those cases where a particular column might appear in more than one place. To support this change, the :class:`.ColumnCollection` has been revised to support duplicate columns as well as to allow integer index access. Fixes: #4753 Change-Id: Ie09a8116f05c367995c1e43623c51e07971d3bf0
* Enable F841Mike Bayer2019-06-201-5/+3
| | | | | | | | | | | This is a very useful assertion which prevents unused variables from being set up allows code to be more readable and sometimes even more efficient. test suites seem to be where the most problems are and there do not seem to be documentation examples that are using this, or at least the linter is not taking effect within rst blocks. Change-Id: I2b3341d8dd14da34879d8425838e66a4b9f8e27d
* Implement new ClauseElement role and coercion systemMike Bayer2019-05-181-5/+19
| | | | | | | | | | | | | | | | | | | | A major refactoring of all the functions handle all detection of Core argument types as well as perform coercions into a new class hierarchy based on "roles", each of which identify a syntactical location within a SQL statement. In contrast to the ClauseElement hierarchy that identifies "what" each object is syntactically, the SQLRole hierarchy identifies the "where does it go" of each object syntactically. From this we define a consistent type checking and coercion system that establishes well defined behviors. This is a breakout of the patch that is reorganizing select() constructs to no longer be in the FromClause hierarchy. Also includes a rename of as_scalar() into scalar_subquery(); deprecates automatic coercion to scalar_subquery(). Partially-fixes: #4617 Change-Id: I26f1e78898693c6b99ef7ea2f4e7dfd0e8e1a1bd
* Do not register the GenericFunction in sql.functions._registryAdrien Berchet2019-05-061-1/+12
| | | | | | | | | | | | | | Fixed that the :class:`.GenericFunction` class was inadvertently registering itself as one of the named functions. Pull request courtesy Adrien Berchet. Fixes: #4653 Closes: #4654 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4654 Pull-request-sha: 1112b89f0d5af8cd5ba88cef744698a79dbdb963 Change-Id: Ia0d366d3bff44a763aa496287814278dff732a19
* Make the GenericFunction registry fully case insensitiveMike Bayer2019-04-301-58/+6
| | | | | | | | | | | | Registered function names based on :class:`.GenericFunction` are now retrieved in a case-insensitive fashion in all cases, removing the deprecation logic from 1.3 which temporarily allowed multiple :class:`.GenericFunction` objects to exist with differing cases. A :class:`.GenericFunction` that replaces another on the same name whether or not it's case sensitive emits a warning before replacing the object. Fixes: #4649 Change-Id: I265ae19833132db07ed5b5ae40c4d24f659b1ab3
* Add case insensitivity feature to GenericFunction.Adrien Berchet2019-04-291-2/+63
| | | | | | | | | | | | | | | | | | | | | The :class:`.GenericFunction` namespace is being migrated so that function names are looked up in a case-insensitive manner, as SQL functions do not collide on case sensitive differences nor is this something which would occur with user-defined functions or stored procedures. Lookups for functions declared with :class:`.GenericFunction` now use a case insensitive scheme, however a deprecation case is supported which allows two or more :class:`.GenericFunction` objects with the same name of different cases to exist, which will cause case sensitive lookups to occur for that particular name, while emitting a warning at function registration time. Thanks to Adrien Berchet for a lot of work on this complicated feature. Fixes: #4569 Closes: #4570 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4570 Pull-request-sha: 37d4f3322b6bace88c99b959cb1916dbbc57610e Change-Id: Ief07c6eb55bf398f6aad85b60ef13ee6d1173109
* Add _cache_key implementation.Mike Bayer2019-04-291-0/+21
| | | | | | | This leverages the work started in #4336 to allow ClauseElement structures to be cachable based on structure, not just identity. Change-Id: Ia99ddeb5353496dd7d61243245685f02b98d8100
* Reimplement .compare() in terms of a visitorMike Bayer2019-04-291-10/+24
| | | | | | | | | | | | Reworked the :meth:`.ClauseElement.compare` methods in terms of a new visitor-based approach, and additionally added test coverage ensuring that all :class:`.ClauseElement` subclasses can be accurately compared against each other in terms of structure. Structural comparison capability is used to a small degree within the ORM currently, however it also may form the basis for new caching features. Fixes: #4336 Change-Id: I581b667d8e1642a6c27165cc9f4aded1c66effc6
* Prevent __init__ from being called for Alias, subclassesMike Bayer2019-02-211-1/+1
| | | | | | | | | | | The :class:`.Alias` class and related subclasses :class:`.CTE`, :class:`.Lateral` and :class:`.TableSample` have been reworked so that it is not possible for a user to construct the objects directly. These constructs require that the standalone construction function or selectable-bound method be used to instantiate new objects. Fixes: #4509 Change-Id: I74ae4786cb3ae625dab33b00bfd6bdc4e1219139
* Remove version directives for 0.6, 0.7, 0.8Mike Bayer2019-01-151-15/+0
| | | | | | | | | - fix a few "seealso"s - ComparableProprerty's "superseded in 0.7" becomes deprecated in 0.7 Backport to currently maintained doc versions 1.2, 1.1 Change-Id: Ib1fcb2df8673dbe5c4ffc47f3896a60d1dfcb4b2
* Merge "use ..deprecated directive w/ version in all cases"mike bayer2019-01-121-0/+16
|\
| * use ..deprecated directive w/ version in all casesMike Bayer2019-01-111-0/+16
| | | | | | | | | | | | | | | | | | 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
* | happy new yearMike Bayer2019-01-111-1/+1
|/ | | | Change-Id: I6a71f4924d046cf306961c58dffccf21e9c03911
* Post black reformattingMike Bayer2019-01-061-26/+30
| | | | | | | | | | | | | 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-061-55/+84
| | | | | | | | | | | | | | 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
* Allow optional *args with base AnsiFunctionMike Bayer2018-11-291-4/+11
| | | | | | | | | | | | | 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
* 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
* support functions "as binary comparison"Mike Bayer2018-07-091-1/+104
| | | | | | | | | 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
* happy new yearMike Bayer2018-01-121-1/+1
| | | | Change-Id: I3ef36bfd0cb0ba62b3123c8cf92370a43156cf8f
* Fix array_agg to accommodate ARRAY argumentsMike Bayer2017-10-061-1/+8
| | | | | | | | | | Fixed bug in :func:`.array_agg` function where passing an argument that is already of type :class:`.ARRAY`, such as a Postgresql :obj:`.postgresql.array` construct, would produce a ``ValueError``, due to the function attempting to nest the arrays. Change-Id: Ibe5f6275d90e4868e6ef8a733de05acd44c05d78 Fixes: #4107
* Implement placeholders for CUBE, ROLLUP, GROUPING SETSreview/mike_bayer/pr_github_383Spitcyn2017-09-131-0/+62
| | | | | | | | Fixes: #3429 Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Change-Id: I870ee7dc801d553c5309c291402ec468b671e9a9 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/383
* Support python3.6Mike Bayer2017-01-131-4/+4
| | | | | | | | | | | Corrects some warnings and adds tox config. Adds DeprecationWarning to the error category. Large sweep for string literals w/ backslashes as this is common in docstrings Co-authored-by: Andrii Soldatenko Fixes: #3886 Change-Id: Ia7c838dfbbe70b262622ed0803d581edc736e085 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/337
* update for 2017 copyrightMike Bayer2017-01-041-1/+1
| | | | Change-Id: I4e8c2aa8fe817bb2af8707410fa0201f938781de
* spelling: Postgresql -> PostgreSQLVille Skyttä2016-10-081-1/+1
|
* Support range specification in window functionPhillip Cloud2016-06-071-2/+8
| | | | | | | Fixes: #3049 Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Change-Id: Ie572095c3e25f70a1e72e1af6858e5edd89fd25e Pull-request: https://github.com/zzzeek/sqlalchemy/pull/264
* Adds parentheses around prints in documentationpr/263jfinkels2016-04-271-7/+7
| | | This makes the docstring example code compatible with both Python 2 and Python 3.
* - further edit the unnest() example to suit PG's esoteric requirementsMike Bayer2016-02-181-4/+6
| | | | exactly
* - use same colname as the alias we give to the PG functionMike Bayer2016-02-161-2/+2
| | | | here, fixes #3652
* - happy new yearMike Bayer2016-01-291-1/+1
|
* - Added :class:`.mysql.JSON` for MySQL 5.7. The JSON type providesMike Bayer2016-01-061-10/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | persistence of JSON values in MySQL as well as basic operator support of "getitem" and "getpath", making use of the ``JSON_EXTRACT`` function in order to refer to individual paths in a JSON structure. fixes #3547 - Added a new type to core :class:`.types.JSON`. This is the base of the PostgreSQL :class:`.postgresql.JSON` type as well as that of the new :class:`.mysql.JSON` type, so that a PG/MySQL-agnostic JSON column may be used. The type features basic index and path searching support. fixes #3619 - reorganization of migration docs etc. to try to refer both to the fixes to JSON that helps Postgresql while at the same time indicating these are new features of the new base JSON type. - a rework of the Array/Indexable system some more, moving things that are specific to Array out of Indexable. - new operators for JSON indexing added to core so that these can be compiled by the PG and MySQL dialects individually - rename sqltypes.Array to sqltypes.ARRAY - as there is no generic Array implementation, this is an uppercase type for now, consistent with the new sqltypes.JSON type that is also not a generic implementation. There may need to be some convention change to handle the case of datatypes that aren't generic, rely upon DB-native implementations, but aren't necessarily all named the same thing.
* - add a postgresql-specific form of array_agg() that injects theMike Bayer2015-08-271-2/+9
| | | | ARRAY type, references #3132
* - Added support for "set-aggregate" functions of the formticket_3516Mike Bayer2015-08-261-7/+152
| | | | | | | | | | | ``<function> WITHIN GROUP (ORDER BY <criteria>)``, using the method :class:`.FunctionElement.within_group`. A series of common set-aggregate functions with return types derived from the set have been added. This includes functions like :class:`.percentile_cont`, :class:`.dense_rank` and others. fixes #1370 - make sure we use func.name for all _literal_as_binds in functions.py so we get consistent naming behavior for parameters.
* - Added support for the SQL-standard function :class:`.array_agg`,Mike Bayer2015-08-261-0/+22
| | | | | | | which automatically returns an :class:`.Array` of the correct type and supports index / slice operations. As arrays are only supported on Postgresql at the moment, only actually works on Postgresql. fixes #3132
* - build out a new base type for Array, as well as new any/all operatorsMike Bayer2015-08-251-1/+11
| | | | | | - any/all work for Array as well as subqueries, accepted by MySQL - Postgresql ARRAY now subclasses Array - fixes #3516
* - copyright 2015Mike Bayer2015-03-101-1/+1
|
* - changelog, migration for pr github:134Mike Bayer2014-10-041-1/+8
|
* renamed aggregatefilter to funcfilter, since it is thatIlja Everilä2014-09-111-7/+7
|
* implementation for <aggregate_fun> FILTER (WHERE ...)Ilja Everilä2014-09-101-1/+23
|
* - Added a supported :meth:`.FunctionElement.alias` method to functions,Mike Bayer2014-07-241-5/+47
| | | | | | | | | e.g. the ``func`` construct. Previously, behavior for this method was undefined. The current behavior mimics that of pre-0.9.4, which is that the function is turned into a single-column FROM clause with the given alias name, where the column itself is anonymously named. fixes #3137
* - apply pep8 formatting to sqlalchemy/sql, sqlalchemy/util, sqlalchemy/dialects,Brian Jarrett2014-07-201-15/+18
| | | | sqlalchemy/orm, sqlalchemy/event, sqlalchemy/testing