diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-04-14 13:15:21 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-04-14 13:15:21 -0400 |
commit | cea03be855514d592b6671fa6dbc074a19a795fb (patch) | |
tree | f127540bda77a4ea5d9935cffedf04d8b01776a9 /lib/sqlalchemy/sql/elements.py | |
parent | a898ade3bc36ca27cf9475d1348249646eb40e95 (diff) | |
download | sqlalchemy-cea03be855514d592b6671fa6dbc074a19a795fb.tar.gz |
Run search and replace of symbolic module names
Replaces a wide array of Sphinx-relative doc references
with an abbreviated absolute form now supported by
zzzeeksphinx.
Change-Id: I94bffcc3f37885ffdde6238767224296339698a2
Diffstat (limited to 'lib/sqlalchemy/sql/elements.py')
-rw-r--r-- | lib/sqlalchemy/sql/elements.py | 380 |
1 files changed, 227 insertions, 153 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index 9689c7a8a..49bb08644 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -5,8 +5,8 @@ # This module is part of SQLAlchemy and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php -"""Core SQL expression elements, including :class:`.ClauseElement`, -:class:`.ColumnElement`, and derived classes. +"""Core SQL expression elements, including :class:`_expression.ClauseElement`, +:class:`_expression.ColumnElement`, and derived classes. """ @@ -88,14 +88,15 @@ def between(expr, lower_bound, upper_bound, symmetric=False): SELECT id, name FROM user WHERE id BETWEEN :id_1 AND :id_2 The :func:`.between` function is a standalone version of the - :meth:`.ColumnElement.between` method available on all + :meth:`_expression.ColumnElement.between` method available on all SQL expressions, as in:: stmt = select([users_table]).where(users_table.c.id.between(5, 7)) All arguments passed to :func:`.between`, including the left side column expression, are coerced from Python scalar values if a - the value is not a :class:`.ColumnElement` subclass. For example, + the value is not a :class:`_expression.ColumnElement` subclass. + For example, three fixed values can be compared as in:: print(between(5, 3, 7)) @@ -104,7 +105,8 @@ def between(expr, lower_bound, upper_bound, symmetric=False): :param_1 BETWEEN :param_2 AND :param_3 - :param expr: a column expression, typically a :class:`.ColumnElement` + :param expr: a column expression, typically a + :class:`_expression.ColumnElement` instance or alternatively a Python scalar expression to be coerced into a column expression, serving as the left side of the ``BETWEEN`` expression. @@ -122,7 +124,7 @@ def between(expr, lower_bound, upper_bound, symmetric=False): .. seealso:: - :meth:`.ColumnElement.between` + :meth:`_expression.ColumnElement.between` """ expr = coercions.expect(roles.ExpressionElementRole, expr) @@ -133,8 +135,10 @@ def literal(value, type_=None): r"""Return a literal clause, bound to a bind parameter. Literal clauses are created automatically when non- - :class:`.ClauseElement` objects (such as strings, ints, dates, etc.) are - used in a comparison operation with a :class:`.ColumnElement` subclass, + :class:`_expression.ClauseElement` objects (such as strings, ints, dates, + etc.) are + used in a comparison operation with a :class:`_expression.ColumnElement` + subclass, such as a :class:`~sqlalchemy.schema.Column` object. Use this function to force the generation of a literal clause, which will be created as a :class:`BindParameter` with a bound value. @@ -166,7 +170,7 @@ def not_(clause): """Return a negation of the given clause, i.e. ``NOT(clause)``. The ``~`` operator is also overloaded on all - :class:`.ColumnElement` subclasses to produce the + :class:`_expression.ColumnElement` subclasses to produce the same result. """ @@ -232,7 +236,7 @@ class ClauseElement( """in the context of binary expression, convert the type of this object to the one given. - applies only to :class:`.ColumnElement` classes. + applies only to :class:`_expression.ColumnElement` classes. """ return self @@ -334,7 +338,7 @@ class ClauseElement( \**kw are arguments consumed by subclass compare() methods and may be used to modify the criteria for comparison. - (see :class:`.ColumnElement`) + (see :class:`_expression.ColumnElement`) """ return traversals.compare(self, other, **kw) @@ -396,15 +400,16 @@ class ClauseElement( def self_group(self, against=None): # type: (Optional[Any]) -> ClauseElement - """Apply a 'grouping' to this :class:`.ClauseElement`. + """Apply a 'grouping' to this :class:`_expression.ClauseElement`. This method is overridden by subclasses to return a "grouping" construct, i.e. parenthesis. In particular it's used by "binary" expressions to provide a grouping around themselves when placed into a - larger expression, as well as by :func:`~.sql.expression.select` + larger expression, as well as by :func:`_expression.select` constructs when placed into the FROM clause of another - :func:`~.sql.expression.select`. (Note that subqueries should be - normally created using the :meth:`.Select.alias` method, as many + :func:`_expression.select`. (Note that subqueries should be + normally created using the :meth:`_expression.Select.alias` method, + as many platforms require nested SELECT statements to be named). As expressions are composed together, the application of @@ -415,13 +420,15 @@ class ClauseElement( an expression like ``x OR (y AND z)`` - AND takes precedence over OR. - The base :meth:`self_group` method of :class:`.ClauseElement` + The base :meth:`self_group` method of + :class:`_expression.ClauseElement` just returns self. """ return self def _ungroup(self): - """Return this :class:`.ClauseElement` without any groupings.""" + """Return this :class:`_expression.ClauseElement` """ + """without any groupings.""" return self @@ -438,7 +445,7 @@ class ClauseElement( :param bind: An ``Engine`` or ``Connection`` from which a ``Compiled`` will be acquired. This argument takes precedence over - this :class:`.ClauseElement`'s bound engine, if any. + this :class:`_expression.ClauseElement`'s bound engine, if any. :param column_keys: Used for INSERT and UPDATE statements, a list of column names which should be present in the VALUES clause of the @@ -447,7 +454,8 @@ class ClauseElement( :param dialect: A ``Dialect`` instance from which a ``Compiled`` will be acquired. This argument takes precedence over the `bind` - argument as well as this :class:`.ClauseElement`'s bound engine, + argument as well as this :class:`_expression.ClauseElement` + 's bound engine, if any. :param inline: Used for INSERT statements, for a dialect which does @@ -553,19 +561,23 @@ class ColumnElement( """Represent a column-oriented SQL expression suitable for usage in the "columns" clause, WHERE clause etc. of a statement. - While the most familiar kind of :class:`.ColumnElement` is the - :class:`.Column` object, :class:`.ColumnElement` serves as the basis + While the most familiar kind of :class:`_expression.ColumnElement` is the + :class:`_schema.Column` object, :class:`_expression.ColumnElement` + serves as the basis for any unit that may be present in a SQL expression, including the expressions themselves, SQL functions, bound parameters, literal expressions, keywords such as ``NULL``, etc. - :class:`.ColumnElement` is the ultimate base class for all such elements. + :class:`_expression.ColumnElement` + is the ultimate base class for all such elements. A wide variety of SQLAlchemy Core functions work at the SQL expression - level, and are intended to accept instances of :class:`.ColumnElement` as + level, and are intended to accept instances of + :class:`_expression.ColumnElement` as arguments. These functions will typically document that they accept a "SQL expression" as an argument. What this means in terms of SQLAlchemy usually refers to an input which is either already in the form of a - :class:`.ColumnElement` object, or a value which can be **coerced** into + :class:`_expression.ColumnElement` object, + or a value which can be **coerced** into one. The coercion rules followed by most, but not all, SQLAlchemy Core functions with regards to SQL expressions are as follows: @@ -575,7 +587,8 @@ class ColumnElement( value". This generally means that a :func:`.bindparam` will be produced featuring the given value embedded into the construct; the resulting :class:`.BindParameter` object is an instance of - :class:`.ColumnElement`. The Python value will ultimately be sent + :class:`_expression.ColumnElement`. + The Python value will ultimately be sent to the DBAPI at execution time as a parameterized argument to the ``execute()`` or ``executemany()`` methods, after SQLAlchemy type-specific converters (e.g. those provided by any associated @@ -585,25 +598,28 @@ class ColumnElement( feature an accessor called ``__clause_element__()``. The Core expression system looks for this method when an object of otherwise unknown type is passed to a function that is looking to coerce the - argument into a :class:`.ColumnElement` and sometimes a - :class:`.SelectBase` expression. It is used within the ORM to + argument into a :class:`_expression.ColumnElement` and sometimes a + :class:`_expression.SelectBase` expression. + It is used within the ORM to convert from ORM-specific objects like mapped classes and mapped attributes into Core expression objects. * The Python ``None`` value is typically interpreted as ``NULL``, which in SQLAlchemy Core produces an instance of :func:`.null`. - A :class:`.ColumnElement` provides the ability to generate new - :class:`.ColumnElement` + A :class:`_expression.ColumnElement` provides the ability to generate new + :class:`_expression.ColumnElement` objects using Python expressions. This means that Python operators such as ``==``, ``!=`` and ``<`` are overloaded to mimic SQL operations, - and allow the instantiation of further :class:`.ColumnElement` instances - which are composed from other, more fundamental :class:`.ColumnElement` + and allow the instantiation of further :class:`_expression.ColumnElement` + instances + which are composed from other, more fundamental + :class:`_expression.ColumnElement` objects. For example, two :class:`.ColumnClause` objects can be added together with the addition operator ``+`` to produce a :class:`.BinaryExpression`. Both :class:`.ColumnClause` and :class:`.BinaryExpression` are subclasses - of :class:`.ColumnElement`:: + of :class:`_expression.ColumnElement`:: >>> from sqlalchemy.sql import column >>> column('a') + column('b') @@ -613,9 +629,9 @@ class ColumnElement( .. seealso:: - :class:`.Column` + :class:`_schema.Column` - :func:`.expression.column` + :func:`_expression.column` """ @@ -801,8 +817,8 @@ class ColumnElement( return s def shares_lineage(self, othercolumn): - """Return True if the given :class:`.ColumnElement` - has a common ancestor to this :class:`.ColumnElement`.""" + """Return True if the given :class:`_expression.ColumnElement` + has a common ancestor to this :class:`_expression.ColumnElement`.""" return bool(self.proxy_set.intersection(othercolumn.proxy_set)) @@ -829,8 +845,9 @@ class ColumnElement( def _make_proxy( self, selectable, name=None, name_is_truncatable=False, **kw ): - """Create a new :class:`.ColumnElement` representing this - :class:`.ColumnElement` as it appears in the select list of a + """Create a new :class:`_expression.ColumnElement` representing this + :class:`_expression.ColumnElement` + as it appears in the select list of a descending selectable. """ @@ -854,15 +871,15 @@ class ColumnElement( def cast(self, type_): """Produce a type cast, i.e. ``CAST(<expression> AS <type>)``. - This is a shortcut to the :func:`~.expression.cast` function. + This is a shortcut to the :func:`_expression.cast` function. .. seealso:: :ref:`coretutorial_casts` - :func:`~.expression.cast` + :func:`_expression.cast` - :func:`~.expression.type_coerce` + :func:`_expression.type_coerce` .. versionadded:: 1.0.7 @@ -872,7 +889,7 @@ class ColumnElement( def label(self, name): """Produce a column label, i.e. ``<columnname> AS <name>``. - This is a shortcut to the :func:`~.expression.label` function. + This is a shortcut to the :func:`_expression.label` function. if 'name' is None, an anonymous label name will be generated. @@ -923,7 +940,8 @@ class ColumnElement( class WrapsColumnExpression(object): - """Mixin that defines a :class:`.ColumnElement` as a wrapper with special + """Mixin that defines a :class:`_expression.ColumnElement` + as a wrapper with special labeling behavior for an expression that already has a name. .. versionadded:: 1.4 @@ -1011,7 +1029,8 @@ class BindParameter(roles.InElementRole, ColumnElement): r"""Produce a "bound expression". The return value is an instance of :class:`.BindParameter`; this - is a :class:`.ColumnElement` subclass which represents a so-called + is a :class:`_expression.ColumnElement` + subclass which represents a so-called "placeholder" value in a SQL expression, the value of which is supplied at the point at which the statement in executed against a database connection. @@ -1041,7 +1060,7 @@ class BindParameter(roles.InElementRole, ColumnElement): In order to populate the value of ``:username`` above, the value would typically be applied at execution time to a method - like :meth:`.Connection.execute`:: + like :meth:`_engine.Connection.execute`:: result = connection.execute(stmt, username='wendy') @@ -1070,7 +1089,7 @@ class BindParameter(roles.InElementRole, ColumnElement): expr = users_table.c.name == 'Wendy' The above expression will produce a :class:`.BinaryExpression` - construct, where the left side is the :class:`.Column` object + construct, where the left side is the :class:`_schema.Column` object representing the ``name`` column, and the right side is a :class:`.BindParameter` representing the literal value:: @@ -1102,7 +1121,7 @@ class BindParameter(roles.InElementRole, ColumnElement): Similarly, :func:`.bindparam` is invoked automatically when working with :term:`CRUD` statements as far as the "VALUES" portion is - concerned. The :func:`~.sql.expression.insert` construct produces an + concerned. The :func:`_expression.insert` construct produces an ``INSERT`` expression which will, at statement execution time, generate bound placeholders based on the arguments passed, as in:: @@ -1114,10 +1133,10 @@ class BindParameter(roles.InElementRole, ColumnElement): INSERT INTO "user" (name) VALUES (%(name)s) {'name': 'Wendy'} - The :class:`~.sql.expression.Insert` construct, at + The :class:`_expression.Insert` construct, at compilation/execution time, rendered a single :func:`.bindparam` mirroring the column name ``name`` as a result of the single ``name`` - parameter we passed to the :meth:`.Connection.execute` method. + parameter we passed to the :meth:`_engine.Connection.execute` method. :param key: the key (e.g. the name) for this bind param. @@ -1440,12 +1459,13 @@ class TextClause( result = connection.execute(t) - The :class:`.Text` construct is produced using the :func:`.text` + The :class:`_expression.TextClause` construct is produced using the + :func:`_expression.text` function; see that function for full documentation. .. seealso:: - :func:`.text` + :func:`_expression.text` """ @@ -1501,7 +1521,8 @@ class TextClause( @classmethod @_document_text_coercion("text", ":func:`.text`", ":paramref:`.text.text`") def _create_text(cls, text, bind=None): - r"""Construct a new :class:`.TextClause` clause, representing + r"""Construct a new :class:`_expression.TextClause` clause, + representing a textual SQL string directly. E.g.:: @@ -1511,7 +1532,8 @@ class TextClause( t = text("SELECT * FROM users") result = connection.execute(t) - The advantages :func:`.text` provides over a plain string are + The advantages :func:`_expression.text` + provides over a plain string are backend-neutral support for bind parameters, per-statement execution options, as well as bind parameter and result-column typing behavior, allowing @@ -1531,12 +1553,15 @@ class TextClause( t = text("SELECT * FROM users WHERE name='\:username'") - The :class:`.TextClause` construct includes methods which can + The :class:`_expression.TextClause` + construct includes methods which can provide information about the bound parameters as well as the column values which would be returned from the textual statement, assuming it's an executable SELECT type of statement. The - :meth:`.TextClause.bindparams` method is used to provide bound - parameter detail, and :meth:`.TextClause.columns` method allows + :meth:`_expression.TextClause.bindparams` + method is used to provide bound + parameter detail, and :meth:`_expression.TextClause.columns` + method allows specification of return columns including names and types:: t = text("SELECT * FROM users WHERE id=:user_id").\ @@ -1546,19 +1571,20 @@ class TextClause( for id, name in connection.execute(t): print(id, name) - The :func:`.text` construct is used in cases when + The :func:`_expression.text` construct is used in cases when a literal string SQL fragment is specified as part of a larger query, such as for the WHERE clause of a SELECT statement:: s = select([users.c.id, users.c.name]).where(text("id=:user_id")) result = connection.execute(s, user_id=12) - :func:`.text` is also used for the construction + :func:`_expression.text` is also used for the construction of a full, standalone statement using plain text. As such, SQLAlchemy refers to it as an :class:`.Executable` object, and it supports the :meth:`Executable.execution_options` method. For example, - a :func:`.text` construct that should be subject to "autocommit" + a :func:`_expression.text` + construct that should be subject to "autocommit" can be set explicitly so using the :paramref:`.Connection.execution_options.autocommit` option:: @@ -1566,7 +1592,8 @@ class TextClause( execution_options(autocommit=True) Note that SQLAlchemy's usual "autocommit" behavior applies to - :func:`.text` constructs implicitly - that is, statements which begin + :func:`_expression.text` constructs implicitly - that is, + statements which begin with a phrase such as ``INSERT``, ``UPDATE``, ``DELETE``, or a variety of other phrases specific to certain backends, will be eligible for autocommit if no transaction is in progress. @@ -1591,7 +1618,7 @@ class TextClause( @_generative def bindparams(self, *binds, **names_to_values): """Establish the values and/or types of bound parameters within - this :class:`.TextClause` construct. + this :class:`_expression.TextClause` construct. Given a text construct such as:: @@ -1599,7 +1626,8 @@ class TextClause( stmt = text("SELECT id, name FROM user WHERE name=:name " "AND timestamp=:timestamp") - the :meth:`.TextClause.bindparams` method can be used to establish + the :meth:`_expression.TextClause.bindparams` + method can be used to establish the initial value of ``:name`` and ``:timestamp``, using simple keyword arguments:: @@ -1635,10 +1663,12 @@ class TextClause( result = connection.execute(stmt, timestamp=datetime.datetime(2012, 10, 8, 15, 12, 5)) - The :meth:`.TextClause.bindparams` method can be called repeatedly, + The :meth:`_expression.TextClause.bindparams` + method can be called repeatedly, where it will re-use existing :class:`.BindParameter` objects to add new information. For example, we can call - :meth:`.TextClause.bindparams` first with typing information, and a + :meth:`_expression.TextClause.bindparams` + first with typing information, and a second time with value information, and it will be combined:: stmt = text("SELECT id, name FROM user WHERE name=:name " @@ -1652,10 +1682,12 @@ class TextClause( timestamp=datetime.datetime(2012, 10, 8, 15, 12, 5) ) - The :meth:`.TextClause.bindparams` method also supports the concept of + The :meth:`_expression.TextClause.bindparams` + method also supports the concept of **unique** bound parameters. These are parameters that are "uniquified" on name at statement compilation time, so that multiple - :func:`.text` constructs may be combined together without the names + :func:`_expression.text` + constructs may be combined together without the names conflicting. To use this feature, specify the :paramref:`.BindParameter.unique` flag on each :func:`.bindparam` object:: @@ -1678,7 +1710,8 @@ class TextClause( UNION ALL select id from table where name=:name_2 .. versionadded:: 1.3.11 Added support for the - :paramref:`.BindParameter.unique` flag to work with :func:`.text` + :paramref:`.BindParameter.unique` flag to work with + :func:`_expression.text` constructs. """ @@ -1717,13 +1750,16 @@ class TextClause( @util.preload_module("sqlalchemy.sql.selectable") def columns(self, *cols, **types): - r"""Turn this :class:`.TextClause` object into a - :class:`.TextualSelect` object that serves the same role as a SELECT + r"""Turn this :class:`_expression.TextClause` object into a + :class:`_expression.TextualSelect` + object that serves the same role as a SELECT statement. - The :class:`.TextualSelect` is part of the :class:`.SelectBase` + The :class:`_expression.TextualSelect` is part of the + :class:`_expression.SelectBase` hierarchy and can be embedded into another statement by using the - :meth:`.TextualSelect.subquery` method to produce a :class:`.Subquery` + :meth:`_expression.TextualSelect.subquery` method to produce a + :class:`.Subquery` object, which can then be SELECTed from. This function essentially bridges the gap between an entirely @@ -1740,14 +1776,17 @@ class TextClause( mytable.join(stmt, mytable.c.name == stmt.c.name) ).where(stmt.c.id > 5) - Above, we pass a series of :func:`.column` elements to the - :meth:`.TextClause.columns` method positionally. These :func:`.column` + Above, we pass a series of :func:`_expression.column` elements to the + :meth:`_expression.TextClause.columns` method positionally. These + :func:`_expression.column` elements now become first class elements upon the - :attr:`.TextualSelect.selected_columns` column collection, which then + :attr:`_expression.TextualSelect.selected_columns` column collection, + which then become part of the :attr:`.Subquery.c` collection after - :meth:`.TextualSelect.subquery` is invoked. + :meth:`_expression.TextualSelect.subquery` is invoked. - The column expressions we pass to :meth:`.TextClause.columns` may + The column expressions we pass to + :meth:`_expression.TextClause.columns` may also be typed; when we do so, these :class:`.TypeEngine` objects become the effective return type of the column, so that SQLAlchemy's result-set-processing systems may be used on the return values. @@ -1777,10 +1816,12 @@ class TextClause( for id, name, timestamp in connection.execute(stmt): print(id, name, timestamp) - The positional form of :meth:`.TextClause.columns` also provides the + The positional form of :meth:`_expression.TextClause.columns` + also provides the unique feature of **positional column targeting**, which is particularly useful when using the ORM with complex textual queries. If - we specify the columns from our model to :meth:`.TextClause.columns`, + we specify the columns from our model to + :meth:`_expression.TextClause.columns`, the result set will match to those columns positionally, meaning the name or origin of the column in the textual SQL doesn't matter:: @@ -1798,20 +1839,24 @@ class TextClause( query = session.query(User).from_statement(stmt).options( contains_eager(User.addresses)) - .. versionadded:: 1.1 the :meth:`.TextClause.columns` method now + .. versionadded:: 1.1 the :meth:`_expression.TextClause.columns` + method now offers positional column targeting in the result set when the column expressions are passed purely positionally. - The :meth:`.TextClause.columns` method provides a direct - route to calling :meth:`.FromClause.subquery` as well as - :meth:`.SelectBase.cte` against a textual SELECT statement:: + The :meth:`_expression.TextClause.columns` method provides a direct + route to calling :meth:`_expression.FromClause.subquery` as well as + :meth:`_expression.SelectBase.cte` + against a textual SELECT statement:: stmt = stmt.columns(id=Integer, name=String).cte('st') stmt = select([sometable]).where(sometable.c.id == stmt.c.id) - :param \*cols: A series of :class:`.ColumnElement` objects, typically - :class:`.Column` objects from a :class:`.Table` or ORM level + :param \*cols: A series of :class:`_expression.ColumnElement` objects, + typically + :class:`_schema.Column` objects from a :class:`_schema.Table` + or ORM level column-mapped attributes, representing a set of columns that this textual string will SELECT from. @@ -2212,7 +2257,8 @@ class BooleanClauseList(ClauseList, ColumnElement): ) The :func:`.and_` operation is also implicit in some cases; - the :meth:`.Select.where` method for example can be invoked multiple + the :meth:`_expression.Select.where` + method for example can be invoked multiple times against a statement, which will have the effect of each clause being combined using :func:`.and_`:: @@ -2477,9 +2523,11 @@ class Case(ColumnElement): The values which are accepted as result values in :paramref:`.case.whens` as well as with :paramref:`.case.else_` are coerced from Python literals into :func:`.bindparam` constructs. - SQL expressions, e.g. :class:`.ColumnElement` constructs, are accepted + SQL expressions, e.g. :class:`_expression.ColumnElement` constructs, + are accepted as well. To coerce a literal string expression into a constant - expression rendered inline, use the :func:`.literal_column` construct, + expression rendered inline, use the :func:`_expression.literal_column` + construct, as in:: from sqlalchemy import case, literal_column @@ -2595,13 +2643,16 @@ class Case(ColumnElement): def literal_column(text, type_=None): r"""Produce a :class:`.ColumnClause` object that has the - :paramref:`.column.is_literal` flag set to True. + :paramref:`_expression.column.is_literal` flag set to True. - :func:`.literal_column` is similar to :func:`.column`, except that + :func:`_expression.literal_column` is similar to + :func:`_expression.column`, except that it is more often used as a "standalone" column expression that renders - exactly as stated; while :func:`.column` stores a string name that + exactly as stated; while :func:`_expression.column` + stores a string name that will be assumed to be part of a table and may be quoted as such, - :func:`.literal_column` can be that, or any other arbitrary column-oriented + :func:`_expression.literal_column` can be that, + or any other arbitrary column-oriented expression. :param text: the text of the expression; can be any SQL expression. @@ -2616,9 +2667,9 @@ def literal_column(text, type_=None): .. seealso:: - :func:`.column` + :func:`_expression.column` - :func:`.text` + :func:`_expression.text` :ref:`sqlexpression_literal_column` @@ -2695,7 +2746,8 @@ class Cast(WrapsColumnExpression, ColumnElement): with a specific type, but does not render the ``CAST`` expression in SQL. - :param expression: A SQL expression, such as a :class:`.ColumnElement` + :param expression: A SQL expression, such as a + :class:`_expression.ColumnElement` expression or a Python string which will be coerced into a bound literal value. @@ -2730,7 +2782,7 @@ class Cast(WrapsColumnExpression, ColumnElement): class TypeCoerce(WrapsColumnExpression, ColumnElement): """Represent a Python-side type-coercion wrapper. - :class:`.TypeCoerce` supplies the :func:`.expression.type_coerce` + :class:`.TypeCoerce` supplies the :func:`_expression.type_coerce` function; see that function for usage details. .. versionchanged:: 1.1 The :func:`.type_coerce` function now produces @@ -2739,7 +2791,7 @@ class TypeCoerce(WrapsColumnExpression, ColumnElement): .. seealso:: - :func:`.expression.type_coerce` + :func:`_expression.type_coerce` :func:`.cast` @@ -2776,7 +2828,7 @@ class TypeCoerce(WrapsColumnExpression, ColumnElement): column remains separate in the list of result columns vs. other type-coerced or direct values of the target column. In order to provide a named label for the expression, use - :meth:`.ColumnElement.label`:: + :meth:`_expression.ColumnElement.label`:: stmt = select([ type_coerce( @@ -2801,7 +2853,8 @@ class TypeCoerce(WrapsColumnExpression, ColumnElement): except that it does not render the ``CAST`` expression in the resulting statement. - :param expression: A SQL expression, such as a :class:`.ColumnElement` + :param expression: A SQL expression, such as a + :class:`_expression.ColumnElement` expression or a Python string which will be coerced into a bound literal value. @@ -2961,7 +3014,8 @@ class UnaryExpression(ColumnElement): Like :func:`.asc` and :func:`.desc`, :func:`.nullsfirst` is typically invoked from the column expression itself using - :meth:`.ColumnElement.nullsfirst`, rather than as its standalone + :meth:`_expression.ColumnElement.nullsfirst`, + rather than as its standalone function version, as in:: stmt = (select([users_table]). @@ -2976,7 +3030,7 @@ class UnaryExpression(ColumnElement): :func:`.nullslast` - :meth:`.Select.order_by` + :meth:`_expression.Select.order_by` """ return UnaryExpression( @@ -3005,7 +3059,8 @@ class UnaryExpression(ColumnElement): Like :func:`.asc` and :func:`.desc`, :func:`.nullslast` is typically invoked from the column expression itself using - :meth:`.ColumnElement.nullslast`, rather than as its standalone + :meth:`_expression.ColumnElement.nullslast`, + rather than as its standalone function version, as in:: stmt = select([users_table]).\ @@ -3019,7 +3074,7 @@ class UnaryExpression(ColumnElement): :func:`.nullsfirst` - :meth:`.Select.order_by` + :meth:`_expression.Select.order_by` """ return UnaryExpression( @@ -3043,13 +3098,15 @@ class UnaryExpression(ColumnElement): SELECT id, name FROM user ORDER BY name DESC The :func:`.desc` function is a standalone version of the - :meth:`.ColumnElement.desc` method available on all SQL expressions, + :meth:`_expression.ColumnElement.desc` + method available on all SQL expressions, e.g.:: stmt = select([users_table]).order_by(users_table.c.name.desc()) - :param column: A :class:`.ColumnElement` (e.g. scalar SQL expression) + :param column: A :class:`_expression.ColumnElement` (e.g. + scalar SQL expression) with which to apply the :func:`.desc` operation. .. seealso:: @@ -3060,7 +3117,7 @@ class UnaryExpression(ColumnElement): :func:`.nullslast` - :meth:`.Select.order_by` + :meth:`_expression.Select.order_by` """ return UnaryExpression( @@ -3083,13 +3140,15 @@ class UnaryExpression(ColumnElement): SELECT id, name FROM user ORDER BY name ASC The :func:`.asc` function is a standalone version of the - :meth:`.ColumnElement.asc` method available on all SQL expressions, + :meth:`_expression.ColumnElement.asc` + method available on all SQL expressions, e.g.:: stmt = select([users_table]).order_by(users_table.c.name.asc()) - :param column: A :class:`.ColumnElement` (e.g. scalar SQL expression) + :param column: A :class:`_expression.ColumnElement` (e.g. + scalar SQL expression) with which to apply the :func:`.asc` operation. .. seealso:: @@ -3100,7 +3159,7 @@ class UnaryExpression(ColumnElement): :func:`.nullslast` - :meth:`.Select.order_by` + :meth:`_expression.Select.order_by` """ return UnaryExpression( @@ -3125,12 +3184,13 @@ class UnaryExpression(ColumnElement): SELECT COUNT(DISTINCT name) FROM user The :func:`.distinct` function is also available as a column-level - method, e.g. :meth:`.ColumnElement.distinct`, as in:: + method, e.g. :meth:`_expression.ColumnElement.distinct`, as in:: stmt = select([func.count(users_table.c.name.distinct())]) The :func:`.distinct` operator is different from the - :meth:`.Select.distinct` method of :class:`.Select`, + :meth:`_expression.Select.distinct` method of + :class:`_expression.Select`, which produces a ``SELECT`` statement with ``DISTINCT`` applied to the result set as a whole, e.g. a ``SELECT DISTINCT`` expression. See that method for further @@ -3138,9 +3198,9 @@ class UnaryExpression(ColumnElement): .. seealso:: - :meth:`.ColumnElement.distinct` + :meth:`_expression.ColumnElement.distinct` - :meth:`.Select.distinct` + :meth:`_expression.Select.distinct` :data:`.func` @@ -3210,7 +3270,7 @@ class CollectionAggregate(UnaryExpression): .. seealso:: - :func:`.expression.all_` + :func:`_expression.all_` """ @@ -3241,7 +3301,7 @@ class CollectionAggregate(UnaryExpression): .. seealso:: - :func:`.expression.any_` + :func:`_expression.any_` """ @@ -3551,7 +3611,7 @@ class Over(ColumnElement): Used against aggregate or so-called "window" functions, for database backends that support window functions. - :func:`~.expression.over` is usually called using + :func:`_expression.over` is usually called using the :meth:`.FunctionElement.over` method, e.g.:: func.row_number().over(order_by=mytable.c.some_column) @@ -3623,7 +3683,7 @@ class Over(ColumnElement): :data:`.expression.func` - :func:`.expression.within_group` + :func:`_expression.within_group` """ self.element = element @@ -3739,7 +3799,7 @@ class WithinGroup(ColumnElement): set aggregate" functions, including :class:`.percentile_cont`, :class:`.rank`, :class:`.dense_rank`, etc. - :func:`~.expression.within_group` is usually called using + :func:`_expression.within_group` is usually called using the :meth:`.FunctionElement.within_group` method, e.g.:: from sqlalchemy import within_group @@ -3765,7 +3825,7 @@ class WithinGroup(ColumnElement): :data:`.expression.func` - :func:`.expression.over` + :func:`_expression.over` """ self.element = element @@ -3904,7 +3964,7 @@ class FunctionFilter(ColumnElement): from sqlalchemy import over, funcfilter over(funcfilter(func.rank(), MyClass.y > 5), order_by='x') - See :func:`~.expression.over` for a full description. + See :func:`_expression.over` for a full description. """ return Over( @@ -3956,17 +4016,18 @@ class Label(roles.LabeledColumnExprRole, ColumnElement): def __init__(self, name, element, type_=None): """Return a :class:`Label` object for the - given :class:`.ColumnElement`. + given :class:`_expression.ColumnElement`. A label changes the name of an element in the columns clause of a ``SELECT`` statement, typically via the ``AS`` SQL keyword. This functionality is more conveniently available via the - :meth:`.ColumnElement.label` method on :class:`.ColumnElement`. + :meth:`_expression.ColumnElement.label` method on + :class:`_expression.ColumnElement`. :param name: label name - :param obj: a :class:`.ColumnElement`. + :param obj: a :class:`_expression.ColumnElement`. """ @@ -4070,8 +4131,8 @@ class ColumnClause( """Represents a column expression from any textual string. The :class:`.ColumnClause`, a lightweight analogue to the - :class:`.Column` class, is typically invoked using the - :func:`.column` function, as in:: + :class:`_schema.Column` class, is typically invoked using the + :func:`_expression.column` function, as in:: from sqlalchemy import column @@ -4083,21 +4144,24 @@ class ColumnClause( SELECT id, name FROM user :class:`.ColumnClause` is the immediate superclass of the schema-specific - :class:`.Column` object. While the :class:`.Column` class has all the + :class:`_schema.Column` object. While the :class:`_schema.Column` + class has all the same capabilities as :class:`.ColumnClause`, the :class:`.ColumnClause` class is usable by itself in those cases where behavioral requirements are limited to simple SQL expression generation. The object has none of the associations with schema-level metadata or with execution-time - behavior that :class:`.Column` does, so in that sense is a "lightweight" - version of :class:`.Column`. + behavior that :class:`_schema.Column` does, + so in that sense is a "lightweight" + version of :class:`_schema.Column`. - Full details on :class:`.ColumnClause` usage is at :func:`.column`. + Full details on :class:`.ColumnClause` usage is at + :func:`_expression.column`. .. seealso:: - :func:`.column` + :func:`_expression.column` - :class:`.Column` + :class:`_schema.Column` """ @@ -4118,7 +4182,8 @@ class ColumnClause( """Produce a :class:`.ColumnClause` object. The :class:`.ColumnClause` is a lightweight analogue to the - :class:`.Column` class. The :func:`.column` function can + :class:`_schema.Column` class. The :func:`_expression.column` + function can be invoked with just a name alone, as in:: from sqlalchemy import column @@ -4130,8 +4195,9 @@ class ColumnClause( SELECT id, name FROM user - Once constructed, :func:`.column` may be used like any other SQL - expression element such as within :func:`~.sql.expression.select` + Once constructed, :func:`_expression.column` + may be used like any other SQL + expression element such as within :func:`_expression.select` constructs:: from sqlalchemy.sql import column @@ -4139,19 +4205,24 @@ class ColumnClause( id, name = column("id"), column("name") stmt = select([id, name]).select_from("user") - The text handled by :func:`.column` is assumed to be handled + The text handled by :func:`_expression.column` + is assumed to be handled like the name of a database column; if the string contains mixed case, special characters, or matches a known reserved word on the target backend, the column expression will render using the quoting behavior determined by the backend. To produce a textual SQL expression that is rendered exactly without any quoting, - use :func:`.literal_column` instead, or pass ``True`` as the - value of :paramref:`.column.is_literal`. Additionally, full SQL - statements are best handled using the :func:`.text` construct. + use :func:`_expression.literal_column` instead, + or pass ``True`` as the + value of :paramref:`_expression.column.is_literal`. Additionally, + full SQL + statements are best handled using the :func:`_expression.text` + construct. - :func:`.column` can be used in a table-like + :func:`_expression.column` can be used in a table-like fashion by combining it with the :func:`.table` function - (which is the lightweight analogue to :class:`.Table`) to produce + (which is the lightweight analogue to :class:`_schema.Table` + ) to produce a working table construct with minimal boilerplate:: from sqlalchemy import table, column, select @@ -4164,36 +4235,37 @@ class ColumnClause( stmt = select([user.c.description]).where(user.c.name == 'wendy') - A :func:`.column` / :func:`.table` construct like that illustrated + A :func:`_expression.column` / :func:`.table` + construct like that illustrated above can be created in an ad-hoc fashion and is not associated with any - :class:`.schema.MetaData`, DDL, or events, unlike its - :class:`.Table` counterpart. + :class:`_schema.MetaData`, DDL, or events, unlike its + :class:`_schema.Table` counterpart. - .. versionchanged:: 1.0.0 :func:`.expression.column` can now + .. versionchanged:: 1.0.0 :func:`_expression.column` can now be imported from the plain ``sqlalchemy`` namespace like any other SQL element. :param text: the text of the element. - :param type: :class:`.types.TypeEngine` object which can associate + :param type: :class:`_types.TypeEngine` object which can associate this :class:`.ColumnClause` with a type. :param is_literal: if True, the :class:`.ColumnClause` is assumed to be an exact expression that will be delivered to the output with no quoting rules applied regardless of case sensitive settings. the - :func:`.literal_column()` function essentially invokes - :func:`.column` while passing ``is_literal=True``. + :func:`_expression.literal_column()` function essentially invokes + :func:`_expression.column` while passing ``is_literal=True``. .. seealso:: - :class:`.Column` + :class:`_schema.Column` - :func:`.literal_column` + :func:`_expression.literal_column` :func:`.table` - :func:`.text` + :func:`_expression.text` :ref:`sqlexpression_literal_column` @@ -4418,9 +4490,11 @@ class quoted_name(util.MemoizedSlots, util.text_type): The :class:`.quoted_name` object is normally created automatically when specifying the name for key schema constructs such as - :class:`.Table`, :class:`.Column`, and others. The class can also be + :class:`_schema.Table`, :class:`_schema.Column`, and others. + The class can also be passed explicitly as the name to any function that receives a name which - can be quoted. Such as to use the :meth:`.Engine.has_table` method with + can be quoted. Such as to use the :meth:`_engine.Engine.has_table` + method with an unconditionally quoted name:: from sqlalchemy import create_engine @@ -4592,7 +4666,7 @@ class conv(_truncated_label): In some situations, such as in migration scripts, we may be rendering the above :class:`.CheckConstraint` with a name that's already been converted. In order to make sure the name isn't double-modified, the - new name is applied using the :func:`.schema.conv` marker. We can + new name is applied using the :func:`_schema.conv` marker. We can use this explicitly as follows:: @@ -4602,7 +4676,7 @@ class conv(_truncated_label): t = Table('t', m, Column('x', Integer), CheckConstraint('x > 5', name=conv('ck_t_x5'))) - Where above, the :func:`.schema.conv` marker indicates that the constraint + Where above, the :func:`_schema.conv` marker indicates that the constraint name here is final, and the name will render as ``"ck_t_x5"`` and not ``"ck_t_ck_t_x5"`` |