
    -h                    	   S r SSKJr  SSKrSSKrSSKrSSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK
Jr  SSK
Jr  SSK
Jr  SSKJr  SSKJr  SSKJr  SSKJ r   SSKJ!r!  SSKJ"r"  SSKJ#r#  S  r$SS! jr%SS" jr&SS# jr'S$ r(\"RR                   " S% S&\	RT                  \\\\ 5      5       r+ " S' S(\	RX                  \	RZ                  \	R\                  \	R^                  \	R`                  \	Rb                  \	Rd                  \	Rf                  \	Rh                  \	Rj                  \Rl                  \+5      r7 " S) S*\85      r9 " S+ S,\	Rt                  \75      r; " S- S.\+5      r< " S/ S0\	Rh                  \	Rj                  \	RZ                  \	R\                  \	R`                  \	Rz                  \	R|                  \	R^                  \	Rt                  \\+5      r? " S1 S2\\	R                  \75      rA\AR                  5          " S3 S4\\	R                  \75      rC\CR                  5          " S5 S6\\	R                  \75      rD\DR                  5          " S7 S8\	Rt                  \	R`                  \	Rb                  \	Rf                  \+5      rE " S9 S:\E\75      rF\FR                  rG\FR                  rH " S; S<\E\75      rI " S= S>\75      rJSS? jrK " S@ SA\9\75      rL " SB SC\9\75      rM " SD SE\75      rN " SF SG\75      rO " SH SI\75      rP " SJ SK\75      rQ " SL SM\Q5      rR " SN SO\9\Q5      rS " SP SQ\75      rT " SR SS\75      rU " ST SU\T5      rV " SV SW\+5      rW " SX SY\W\75      rX\#R                  " SZ5      rZ\#R                  " S[5      r[ " S\ S]\75      r\ " S^ S_\75      r] " S` Sa\75      r^ " Sb Sc\	R                  \75      r` " Sd Se\75      ra " Sf Sg\	R                  \	R                  \	R                  \\a5      rd " Sh Si\a5      re " Sj Sk\75      rf " Sl Sm\\+5      rg " Sn So\g5      rh " Sp Sq\g5      ri " Sr Ss\g5      rj " St Su\#R                  \#R                  5      rmSv rnSw roSSx jrp " Sy Sz\5      rq " S{ S|\m5      rr " S} S~\r5      rs\#R                  " S5      rt \rru " S S\r5      rvg)zCore SQL expression elements, including :class:`_expression.ClauseElement`,
:class:`_expression.ColumnElement`, and derived classes.

    )unicode_literalsN   )	coercions)	operators)roles)
traversals)type_api)	Annotated)SupportsWrappingAnnotations)_clone)_generative)
Executable)HasMemoized)	Immutable)NO_ARG)PARSE_AUTOCOMMIT)SingletonConstant)_document_text_coercion)HasCopyInternals)MemoizedHasCacheKey)NO_CACHE)cloned_traverse)InternalTraversal)traverse)Traversible   )exc)
inspection)utilc                     [         R                  " [        R                  U 5      n[	        U[        U5      [        R                  UR                  S9$ )an  Return the clause ``expression COLLATE collation``.

e.g.::

    collate(mycolumn, 'utf8_bin')

produces::

    mycolumn COLLATE utf8_bin

The collation expression is also quoted if it is a case sensitive
identifier, e.g. contains uppercase characters.

.. versionchanged:: 1.2 quoting is automatically applied to COLLATE
   expressions if they are case sensitive.

type_)	r   expectr   ExpressionElementRoleBinaryExpressionCollationClauser   collatetype)
expression	collationexprs      lC:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\sqlalchemy/sql/elements.pyr'   r'   /   sA    & E77DDoi()*;*;499     c                 l    [         R                  " [        R                  U 5      n U R	                  XUS9$ )a  Produce a ``BETWEEN`` predicate clause.

E.g.::

    from sqlalchemy import between
    stmt = select(users_table).where(between(users_table.c.id, 5, 7))

Would produce SQL resembling::

    SELECT id, name FROM user WHERE id BETWEEN :id_1 AND :id_2

The :func:`.between` function is a standalone version of the
: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:`_expression.ColumnElement` subclass.
For example,
three fixed values can be compared as in::

    print(between(5, 3, 7))

Which would produce::

    :param_1 BETWEEN :param_2 AND :param_3

: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.

:param lower_bound: a column or Python scalar expression serving as the
 lower bound of the right side of the ``BETWEEN`` expression.

:param upper_bound: a column or Python scalar expression serving as the
 upper bound of the right side of the ``BETWEEN`` expression.

:param symmetric: if True, will render " BETWEEN SYMMETRIC ". Note
 that not all databases support this syntax.

 .. versionadded:: 0.9.5

.. seealso::

    :meth:`_expression.ColumnElement.between`

)	symmetric)r   r#   r   r$   between)r+   lower_boundupper_boundr/   s       r,   r0   r0   H   s0    h E77>D<<I<FFr-   c                 H    [         R                  " [        R                  XS9$ )a  Return a literal clause, bound to a bind parameter.

Literal clauses are created automatically when non-
: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.

:param value: the value to be bound. Can be any Python object supported by
    the underlying DB-API, or is translatable via the given type argument.

:param type\_: an optional :class:`~sqlalchemy.types.TypeEngine` which
    will provide bind-parameter translation for this literal.

r!   )r   r#   r   LiteralValueRole)valuer"   s     r,   literalr6      s    & E22EGGr-   c                     [        U SUSSS9$ )a`  Create an 'OUT' parameter for usage in functions (stored procedures),
for databases which support them.

The ``outparam`` can be used like a regular function parameter.
The "output" value will be available from the
:class:`~sqlalchemy.engine.CursorResult` object via its ``out_parameters``
attribute, which returns a dictionary containing the values.

NFT)r"   unique
isoutparam)BindParameter)keyr"   s     r,   outparamr<      s     d%$OOr-   c                 t    [         R                  " [        R                  " [        R
                  U 5      5      $ )zReturn a negation of the given clause, i.e. ``NOT(clause)``.

The ``~`` operator is also overloaded on all
:class:`_expression.ColumnElement` subclasses to produce the
same result.

)r   invr   r#   r   r$   clauses    r,   not_rA      s&     ==))%*E*EvNOOr-   c                      \ rS rSrSrSr\R                  " 5       r Sr	Sr
/ rSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSr Sr!S r"S	 r#S
 r$S r%\&S 5       r'\(RR                  S 5       r*\&S 5       r+S r, S"S jr-S r.S r/S r0S r1S#S jr2S r3\Rh                  " S5      \Rh                  " S5      S$S j5       5       r5    S%S jr6S r7S r8S r9S r:S r;\;r<S  r=S!r>g)&ClauseElement   zKBase class for elements of a programmatically constructed SQL
expression.

r@   FdefaultNTc                 <    [         R                  " U5      U l        U $ N)r   immutabledict_propagate_attrs)selfvaluess     r,   _set_propagate_attrs"ClauseElement._set_propagate_attrs   s     !% 2 26 :r-   c                    U R                   nU R                  R                  U R                  5      nU(       aJ  U R                  R	                  5       R                  5        VVs0 s H  u  pEXB;  d  M  XE_M     snnUl        OU R                  R	                  5       Ul        U R                  nUb  Xcl        U$ U Ul        U$ s  snnf )zCreate a shallow copy of this ClauseElement.

This method may be used by a generative API.  Its also used as
part of the "deep" copy afforded by a traversal that combines
the _copy_internals() method.

)_memoized_keys	__class____new____dict__copyitems_is_clone_of)rJ   kwskipckvccs          r,   r   ClauseElement._clone   s     ""NN""4>>2 "&!3!3!5!;!;!=!=!=AJ ++-AJ !~ 48s   $C3Cc                     U $ )za hook to allow the right side of a binary expression to respond
to a negation of the binary expression.

Used for the special case of expanding bind parameter with IN.

 )rJ   
negated_oporiginal_ops      r,   _negate_in_binaryClauseElement._negate_in_binary  	     r-   c                     U $ )zin the context of binary expression, convert the type of this
object to the one given.

applies only to :class:`_expression.ColumnElement` classes.

r^   rJ   r"   s     r,   _with_binary_element_type'ClauseElement._with_binary_element_type  rc   r-   c                     U R                   $ )a  return the 'constructor' for this ClauseElement.

This is for the purposes for creating a new object of
this type.   Usually, its just the element's __class__.
However, the "Annotated" version of the object overrides
to return the class of its proxied element.

rP   rJ   s    r,   _constructorClauseElement._constructor  s     ~~r-   c                 ~    [         R                  " 5       nU nUb"  UR                  U5        UR                  nUb  M"  U$ )zReturn the set consisting all cloned ancestors of this
ClauseElement.

Includes this ClauseElement.  This accessor tends to be used for
FromClause objects to identify 'equivalent' FROM clauses, regardless
of transformative operations.

)r   
column_setaddrU   )rJ   sfs      r,   _cloned_setClauseElement._cloned_set&  s>     OO mEE!HA m r-   c                     [        S5      e)NzFThis SQL expression has no entity namespace with which to filter from.)AttributeErrorrj   s    r,   entity_namespaceClauseElement.entity_namespace=  s    )
 	
r-   c                     U R                   R                  5       nUR                  SS 5        UR                  SS 5        U$ )NrU   _generate_cache_key)rR   rS   pop)rJ   ds     r,   __getstate__ClauseElement.__getstate__D  s6    MM 	nd#	#T*r-   c                     U(       d  U R                   (       a  UR                  XX45      $ [        R                  " U 5      erG   )supports_execution_execute_clauseelementr   ObjectNotExecutableError)rJ   
connectionmultiparamsparamsexecution_options_forces         r,   _execute_on_connection$ClauseElement._execute_on_connectionJ  s:     T,,446  ..t44r-   c                 &    U R                  SX5      $ )zReturn a copy with :func:`_expression.bindparam` elements
replaced.

Same functionality as :meth:`_expression.ClauseElement.params`,
except adds `unique=True`
to affected bind parameters so that multiple statements can be
used.

T_replace_paramsrJ   optionaldictkwargss      r,   unique_paramsClauseElement.unique_paramsT  s     ##D,??r-   c                 &    U R                  SX5      $ )at  Return a copy with :func:`_expression.bindparam` elements
replaced.

Returns a copy of this ClauseElement with
:func:`_expression.bindparam`
elements replaced with values taken from the given dictionary::

  >>> clause = column('x') + bindparam('foo')
  >>> print(clause.compile().params)
  {'foo':None}
  >>> print(clause.params({'foo':7}).compile().params)
  {'foo':7}

Fr   r   s      r,   r   ClauseElement.params`  s     ##E<@@r-   c                    ^^ [        U5      S:X  a  TR                  US   5        O%[        U5      S:  a  [        R                  " S5      eUU4S jn[	        U SSS.SU05      $ )Nr   r   z9params() takes zero or one positional dictionary argumentc                    > U R                   T;   a  TU R                      U l        SU l        T(       a  U R                  5         g g NF)r;   r5   required_convert_to_unique)bindr   r8   s    r,   visit_bindparam6ClauseElement._replace_params.<locals>.visit_bindparamz  s:    xx6!#DHH-
 %'') r-   T)maintain_keydetect_subquery_cols	bindparam)lenupdater   ArgumentErrorr   )rJ   r8   r   r   r   s    ` ` r,   r   ClauseElement._replace_paramsq  sj    |!MM,q/*"##K 	* !4@/*
 	
r-   c                 0    [         R                  " X40 UD6$ )a]  Compare this :class:`_expression.ClauseElement` to
the given :class:`_expression.ClauseElement`.

Subclasses should override the default behavior, which is a
straight identity comparison.

\**kw are arguments consumed by subclass ``compare()`` methods and
may be used to modify the criteria for comparison
(see :class:`_expression.ColumnElement`).

)r   compare)rJ   otherrV   s      r,   r   ClauseElement.compare  s     !!$444r-   c                     U $ )a   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:`_expression.select`
constructs when placed into the FROM clause of another
: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
:meth:`self_group` is automatic - end-user code should never
need to use this method directly.  Note that SQLAlchemy's
clause constructs take operator precedence into account -
so parenthesis might not be needed, for example, in
an expression like ``x OR (y AND z)`` - AND takes precedence
over OR.

The base :meth:`self_group` method of
:class:`_expression.ClauseElement`
just returns self.
r^   rJ   againsts     r,   
self_groupClauseElement.self_group  s	    2 r-   c                     U $ )zFReturn this :class:`_expression.ClauseElement`
without any groupings.
r^   rj   s    r,   _ungroupClauseElement._ungroup  s	    
 r-   zsqlalchemy.engine.defaultzsqlalchemy.engine.urlc                    U(       d  U(       a  UR                   nOU R                  (       a  U R                  R                   nOU R                  S:X  a+  [        R                  R
                  nUR                  5       nOR[        R                  R                  nUR                  R                  U R                  5      R                  5       " 5       nU R                  " U40 UD6$ )a;  Compile this SQL expression.

The return value is a :class:`~.Compiled` object.
Calling ``str()`` or ``unicode()`` on the returned value will yield a
string representation of the result. The
:class:`~.Compiled` object also can return a
dictionary of bind parameter names and values
using the ``params`` accessor.

:param bind: An ``Engine`` or ``Connection`` from which a
    ``Compiled`` will be acquired. This argument takes precedence over
    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
    compiled statement. If ``None``, all columns from the target table
    object are rendered.

: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:`_expression.ClauseElement`
    's bound engine,
    if any.

:param compile_kwargs: optional dictionary of additional parameters
    that will be passed through to the compiler within all "visit"
    methods.  This allows any custom flag to be passed through to
    a custom compilation construct, for example.  It is also used
    for the case of passing the ``literal_binds`` flag through::

        from sqlalchemy.sql import table, column, select

        t = table('t', column('x'))

        s = select(t).where(t.c.x == 5)

        print(s.compile(compile_kwargs={"literal_binds": True}))

    .. versionadded:: 0.9.0

.. seealso::

    :ref:`faq_sql_expression_string`

rE   )dialectr   stringify_dialectr   	preloadedengine_defaultStrCompileDialect
engine_urlURLcreateget_dialect	_compiler)rJ   r   r   rV   rE   urls         r,   compileClauseElement.compile  s    b ,,))++))Y6"nn;;G%779G..33C!ggnn..!km$ &G ~~g,,,r-   c                    Ub"  UR                   (       a  U R                  5       nOS nU(       ag  Uu  pUU[        U5      [        U5      U4n
UR	                  U
5      nUc)  UR
                  nU R                  " U4UUUUS.UD6nXU
'   OaUR                  nOTS n	U R                  " U4UUUUS.UD6nUR                   (       d  UR                  nOUc  UR                  nOUR                  nXU4$ )N)	cache_keycolumn_keysfor_executemanyschema_translate_map)_supports_statement_cachery   tupleboolget
CACHE_MISSr   	CACHE_HITNO_DIALECT_SUPPORTCACHING_DISABLEDNO_CACHE_KEY)rJ   r   compiled_cacher   r   r   rV   elem_cache_keyr   extracted_paramsr;   compiled_sql	cache_hits                r,   _compile_w_cacheClauseElement._compile_w_cache  s$    %'*K*K!557N!N*8'Ik")*C *--c2L##..	#~~ , +$3)=    '3s##--	#>>(' /%9 L 44#66	'#44	#00	y88r-   c                 (    UR                   " X40 UD6$ )zFReturn a compiler appropriate for this ClauseElement, given a
Dialect.)statement_compiler)rJ   r   rV   s      r,   r   ClauseElement._compiler3  s     ))'>2>>r-   c                     [         R                  (       a  [        U R                  5       5      $ [	        U R                  5       5      R                  SS5      $ Nasciibackslashreplace)r   py3kstrr   unicodeencoderj   s    r,   __str__ClauseElement.__str__9  s>    99t||~&&4<<>*11+ r-   c                 \    [        U S5      (       a  U R                  $ U R                  5       $ )Nnegation_clause)hasattrr   _negaterj   s    r,   
__invert__ClauseElement.__invert__A  s*     4*++'''<<>!r-   c                 h    [        U R                  [        R                  S9[        R                  S9$ )Nr   )operator)UnaryExpressionr   r   r>   rj   s    r,   r   ClauseElement._negateI  s'    OOIMMO2Y]]
 	
r-   c                     [        S5      eNz+Boolean value of this clause is not defined)	TypeErrorrj   s    r,   __bool__ClauseElement.__bool__N  s    EFFr-   c                     U R                   nUc  [        R                  U 5      $ SU R                  U R                  R
                  [        U 5      U4-  $ )Nz<%s.%s at 0x%x; %s>)descriptionobject__repr__
__module__rP   __name__id)rJ   friendlys     r,   r   ClauseElement.__repr__S  sR    ##??4(((''4	,  r-   )rI   FrG   )NN)NNFN)?r   r   __qualname____firstlineno____doc____visit_name__r   rH   rI   r   r   _from_objectsr   r   rU   is_clause_elementis_selectable!_gen_static_annotations_cache_key	_is_table_is_textual_is_from_clause_is_returns_rows_is_text_clause_is_from_container_is_select_container_is_select_statement_is_bind_parameter_is_clause_list_is_lambda_element_is_singleton_constant_is_immutable_is_star_order_by_label_element_cache_key_traversalrL   r   ra   rf   propertyrk   r   memoized_attributerr   rv   r|   r   r   r   r   r   r   r   preload_moduler   r   r   r   r   r   r   __nonzero__r   __static_attributes__r^   r-   r,   rC   rC      s   
 N))+
 !MDKLM(-%IKOO  O"MH"8 	 	 ## $, 
 
 JO5
@A"
,56 
45	01>- 2 6>-F !89t?"

G K
r-   rC   c                     ^  \ rS rSrSrSrSr/ rSrSr	 Sr
 \R                  S 5       r\S 5       r\S	 5       r\S
 5       rSr Sr SrSrS-S jrU 4S jr\R2                  S 5       r\R                  S 5       rS rS rS rS rS.S jr \S 5       r!\S 5       r"\R2                  S 5       r#\R2                  S 5       r$S r%S r&S r'\R                  S 5       r(\R                  S 5       r) S/S jr*S r+S  r,S-S! jr-\R2                  S" 5       r.\R2                  S# 5       r/\\R`                  " S$S%5      S& 5       5       r1\\R`                  " S$S'5      S( 5       5       r2S) r3\R2                  S* 5       r4\R2                  S+ 5       r5S, r6Sr7U =r8$ )0ColumnElementi`  a  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:`_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:`_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:`_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:`_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:

    * a literal Python value, such as a string, integer or floating
      point value, boolean, datetime, ``Decimal`` object, or virtually
      any other Python object, will be coerced into a "literal bound
      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:`_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
      :class:`.TypeEngine` objects) are applied to the value.

    * any special object value, typically ORM-level constructs, which
      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:`_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:`_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:`_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:`_expression.ColumnElement`::

    >>> from sqlalchemy.sql import column
    >>> column('a') + column('b')
    <sqlalchemy.sql.expression.BinaryExpression object at 0x101029dd0>
    >>> print(column('a') + column('b'))
    a + b

.. seealso::

    :class:`_schema.Column`

    :func:`_expression.column`

column_elementFr^   Nc                     U R                   $ )a$  A label-based version of 'key' that in some circumstances refers
to this object in a Python namespace.


_tq_key_label comes into play when a select() statement is constructed
with apply_labels(); in this case, all Column objects in the ``.c``
collection are rendered as <tablename>_<columnname> in SQL; this is
essentially the value of ._label. But to locate those columns in the
``.c`` collection, the name is along the lines of <tablename>_<key>;
that's the typical value of .key_label.

.. versionchanged:: 1.4.21 renamed from ``._key_label``

)
_proxy_keyrj   s    r,   _tq_key_labelColumnElement._tq_key_label  s      r-   c                     U R                   $ )z legacy; renamed to _tq_key_label)r  rj   s    r,   
_key_labelColumnElement._key_label  s     !!!r-   c                     U R                   $ )zlegacy; renamed to _tq_label)	_tq_labelrj   s    r,   _labelColumnElement._label  s     ~~r-   c                     [        U SS5      $ )a  the 'name' that naturally applies this element when rendered in
SQL.

Concretely, this is the "name" of a column or a label in a
SELECT statement; ``<columnname>`` and ``<labelname>`` below::

    SELECT <columnmame> FROM table

    SELECT column AS <labelname> FROM table

Above, the two names noted will be what's present in the DBAPI
``cursor.description`` as the names.

If this attribute returns ``None``, it means that the SQL element as
written does not have a 100% fully predictable "name" that would appear
in the ``cursor.description``. Examples include SQL functions, CAST
functions, etc. While such things do return names in
``cursor.description``, they are only predictable on a
database-specific basis; e.g. an expression like ``MAX(table.col)`` may
appear as the string ``max`` on one database (like PostgreSQL) or may
appear as the whole expression ``max(table.col)`` on SQLite.

The default implementation looks for a ``.name`` attribute on the
object, as has been the precedent established in SQLAlchemy for many
years.  An exception is made on the ``FunctionElement`` subclass
so that the return value is always ``None``.

.. versionadded:: 1.4.21



nameN)getattrrj   s    r,   _non_anon_labelColumnElement._non_anon_label  s    D tVT**r-   Tc                 ~   U[         R                  [         R                  [         R                  4;   aZ  U R                  R
                  [        R                  R
                  L a)  [        U [         R                  [         R                  5      $ U[         R                  [         R                  4;   a  [        U 5      $ U $ rG   )r   and_or__asboolr(   _type_affinityr	   BOOLEANTYPE	AsBooleanis_trueis_falseany_opall_opGroupingr   s     r,   r   ColumnElement.self_group1  s    		y7H7HII		((H,@,@,O,OOT9#4#4i6H6HII))9+;+;<<D>!Kr-   c                    > U R                   R                  [        R                  R                  L a)  [	        U [
        R                  [
        R                  5      $ [        [        U ]+  5       $ rG   )r(   r,  r	   r-  r.  r   r0  r/  superr  r   rJ   rP   s    r,   r   ColumnElement._negate<  sL    99##x';';'J'JJT9#5#5y7H7HII577r-   c                 "    [         R                  $ rG   r	   NULLTYPErj   s    r,   r(   ColumnElement.typeB         r-   c                      U R                   R                  nU" U 5      $ ! [         a5  n[        R                  " [        SU R                   -  5      US9   S nAg S nAff = f)NzOObject %r associated with '.type' attribute is not a TypeEngine class or objectreplace_context)r(   comparator_factoryru   r   raise_r   )rJ   rA  errs      r,   
comparatorColumnElement.comparatorF  sa    	,!%!=!= &d++  	KK:<@IIF !$	s     
A+AAc                 :    U R                   R                  U5        g rG   )rR   r   rJ   states     r,   __setstate__ColumnElement.__setstate__U  s    U#r-   c                     [        U R                  U5      $ ! [         ad  n[        R                  " [        S[        U 5      R                  < S[        U R                  5      R                  < SU< 35      US9   S nAg S nAff = f)NzNeither z object nor z object has an attribute r?  )r%  rD  ru   r   rB  r(   r   )rJ   r;   rC  s      r,   __getattr__ColumnElement.__getattr__X  sj    	4??C00 	KK T
++T__-66	 !$
	s    
BABBc                 .    U" U R                   /UQ70 UD6$ rG   rD  rJ   opr   r   s       r,   operateColumnElement.operateh  s    $//4E4V44r-   c                 (    U" X R                   40 UD6$ rG   rO  rP  s       r,   reverse_operateColumnElement.reverse_operatek  s    %3F33r-   c           
      4    [        S UUUU R                  SUS9$ )NT)_compared_to_operatorr"   _compared_to_typer8   	expanding)r:   r(   rJ   r   objr"   rZ  s        r,   _bind_paramColumnElement._bind_paramn  s(    "*"ii
 	
r-   c                     U $ )zNReturn a column expression.

Part of the inspection interface; returns self.

r^   rj   s    r,   r)   ColumnElement.expressiony  rc   r-   c                     U 4$ rG   r^   rj   s    r,   _select_iterableColumnElement._select_iterable  	    wr-   c                 P    [         R                  " S U R                   5       5      $ )Nc              3   J   #    U  H  oR                   (       a  M  Uv   M     g 7frG   )_proxies).0rX   s     r,   	<genexpr>-ColumnElement.base_columns.<locals>.<genexpr>  s     K.Q

qq.s   #	#)r   rn   	proxy_setrj   s    r,   base_columnsColumnElement.base_columns  s    K$..KKKr-   c                     [         R                  " U R                  5       /5      nU R                   H  nUR	                  UR
                  5        M      U$ rG   )r   rn   _deannotaterg  r   rk  rJ   rp   rX   s      r,   rk  ColumnElement.proxy_set  s?    OOT--/01AHHQ[[! r-   c                 p    U /nU R                    H"  nUR                  UR                  5       5        M$     U$ )zAn 'uncached' version of proxy set.

This is so that we can read annotations from the list of columns
without breaking the caching of the above proxy_set.

)rg  extend_uncached_proxy_listrp  s      r,   rt  "ColumnElement._uncached_proxy_list  s3     FAHHQ++-. r-   c                 ^    [        U R                  R                  UR                  5      5      $ )z}Return True if the given :class:`_expression.ColumnElement`
has a common ancestor to this :class:`_expression.ColumnElement`.)r   rk  intersection)rJ   othercolumns     r,   shares_lineageColumnElement.shares_lineage  s$     DNN//0E0EFGGr-   c                     [        US5      =(       a,    [        U S5      =(       a    UR                  U R                  :H  $ )z`Return True if the given column element compares to this one
when targeting within a result row.r$  )r   r$  rJ   r   s     r,   _compare_name_for_result&ColumnElement._compare_name_for_result  s7    
 E6" (f%(

dii'	
r-   c                     U R                   (       a  SU R                   ;   a  U R                   S   $ U R                  nU(       d  U R                  n[        U[        5      (       a  g U$ )N	proxy_key)_annotationsr;   r&  
isinstance_anonymous_labelrJ   r$  s     r,   r  ColumnElement._proxy_key  sX    0A0A!A$$[11xx
 ''Dd,--Kr-   c                     [        U SS5      b  gU R                  (       a  SU R                  ;   a  U R                  S   $ g)a4  a suggested label to use in the case that the column has no name,
which should be used if possible as the explicit 'AS <label>'
where this expression would normally have an anon label.

this is essentially mostly what _proxy_key does except it returns
None if the column has a normal name that can be used.

r$  Nr  )r%  r  rj   s    r,   _expression_labelColumnElement._expression_label  s@     4&2;$2C2C#C$$[11r-   c                 n   Uc  U R                   nUc  U R                  nOUn[        U(       a%  [        R                  " [
        R                  U5      OU[        U SS5      US9nUR                  Ul        U /Ul	        UR                  b*  UR                  R                  R                  U5      Ul
        X64$ )zCreate a new :class:`_expression.ColumnElement` representing this
:class:`_expression.ColumnElement` as it appears in the select list of
a descending selectable.

Nr(   )r"   _selectable)_anon_name_labelr  ColumnClauser   r#   r   TruncatedLabelRoler%  rI   rg  rU   columnsr   )rJ   
selectabler$  r;   name_is_truncatablerV   cos          r,   _make_proxyColumnElement._make_proxy  s     <((D{ooC" U55t<$-"
 )99f"".(55==AA#FBOwr-   c                     [        X5      $ )a   Produce a type cast, i.e. ``CAST(<expression> AS <type>)``.

This is a shortcut to the :func:`_expression.cast` function.

.. seealso::

    :ref:`tutorial_casts`

    :func:`_expression.cast`

    :func:`_expression.type_coerce`

.. versionadded:: 1.0.7

)Castre   s     r,   castColumnElement.cast  s      D  r-   c                 .    [        XU R                  5      $ )zProduce a column label, i.e. ``<columnname> AS <name>``.

This is a shortcut to the :func:`_expression.label` function.

If 'name' is ``None``, an anonymous label name will be generated.

)Labelr(   r  s     r,   labelColumnElement.label   s     T++r-   c                 B   U R                   b  U R                   n U R                   b  M  [        U 5      nU(       a  US:  d   eU(       d   eUS-  U-  nUS-   n[        U[        5      (       a  [        R	                  USUS9$ [        R	                  X1=(       d    S5      $ )Ni      _ )enclosing_labelanon)rU   hashr  r  safe_construct)rJ   seedadd_hash
hash_values       r,   _anon_labelColumnElement._anon_label
  s    +$$D + $Z
 w'''K4$*h6J #:Dd,--#22B 3    ..z>6JJr-   c                 >    [        U SS5      nU R                  U5      $ )ag  Provides a constant 'anonymous label' for this ColumnElement.

This is a label() expression which will be named at compile time.
The same label() is returned each time ``anon_label`` is called so
that expressions can reference ``anon_label`` multiple times,
producing the same label name at compile time.

The compiler uses this function automatically at compile time
for expressions that are known to be 'unnamed' like binary
expressions and function calls.

.. versionchanged:: 1.4.9 - this attribute was not intended to be
   public and is renamed to _anon_name_label.  anon_name exists
   for backwards compat

r$  Nr%  r  r  s     r,   r  ColumnElement._anon_name_label,  s#    $ tVT*%%r-   c                 8    U R                  U R                  5      $ )a  Provides a constant 'anonymous key label' for this ColumnElement.

Compare to ``anon_label``, except that the "key" of the column,
if available, is used to generate the label.

This is used when a deduplicating key is placed into the columns
collection of a selectable.

.. versionchanged:: 1.4.9 - this attribute was not intended to be
   public and is renamed to _anon_key_label.  anon_key_label exists
   for backwards compat

)r  r  rj   s    r,   _anon_key_labelColumnElement._anon_key_labelA  s     00r-   1.4zqThe :attr:`_expression.ColumnElement.anon_label` attribute is now private, and the public accessor is deprecated.c                     U R                   $ rG   )r  rj   s    r,   
anon_labelColumnElement.anon_labelR  s     $$$r-   zuThe :attr:`_expression.ColumnElement.anon_key_label` attribute is now private, and the public accessor is deprecated.c                     U R                   $ rG   )r  rj   s    r,   anon_key_labelColumnElement.anon_key_label[  s     ###r-   c                 b    [        U SS5      nUc  U R                  U5      $ U R                  X!S9$ )a  label to apply to a column that is anon labeled, but repeated
in the SELECT, so that we have to make an "extra anon" label that
disambiguates it from the previous appearance.

these labels come out like "foo_bar_id__1" and have double underscores
in them.

r$  Nr  )r%  _dedupe_anon_tq_label_idxr  rJ   idxr  s      r,   _dedupe_anon_label_idx$ColumnElement._dedupe_anon_label_idxd  s>     fd+ =11#66##E#88r-   c                 :    U R                  [        U SS 5      5      $ Nr   r  r%  rj   s    r,   _anon_tq_labelColumnElement._anon_tq_label{  s    k4 @AAr-   c                 :    U R                  [        U SS 5      5      $ )Nr  r  rj   s    r,   _anon_tq_key_label ColumnElement._anon_tq_key_label  s    ot DEEr-   c                 L    [        U SS 5      =(       d    SnU R                  X!S9$ )Nr   r  r  r  r  s      r,   r  'ColumnElement._dedupe_anon_tq_label_idx  s)    k40:F44r-   rG   r   )NNF)9r   r   r   r   r   r   primary_keyforeign_keysrg  r   r;   r   r  r  r  r  r!  r&  _render_label_in_columns_clause_allow_label_resolve_is_implicitly_boolean
_alt_namesr   r   r   memoized_propertyr(   rD  rI  rL  rR  rU  r]  r)   rb  rl  rk  rt  ry  r}  r  r  r  r  r  r  r  r  
deprecatedr  r  r  r  r  r  r  __classcell__ri   s   @r,   r  r  `  s   KZ &NKLHI  C ## $" " "   !+ !+F '+#   #J	8 
! ! ##, $,$ 54	
     
L L 
 
H
 ## $" ## $$ DI:!$, KD 
& &( 
1 1  	__	:
% % 	__	>
$ $9. 
B B 
F F5 5r-   r  c                      ^  \ rS rSrSr\S 5       r\S 5       r\r\S 5       r	\U 4S j5       r
S r\U 4S j5       rS	rU =r$ )
WrapsColumnExpressioni  zMixin that defines a :class:`_expression.ColumnElement`
as a wrapper with special
labeling behavior for an expression that already has a name.

.. versionadded:: 1.4

.. seealso::

    :ref:`change_4449`


c                     [        5       erG   NotImplementedErrorrj   s    r,   wrapped_column_expression/WrapsColumnExpression.wrapped_column_expression  s    !##r-   c                 V    U R                   n[        US5      (       a  UR                  $ g r  )r  r   r   )rJ   wces     r,   r   WrapsColumnExpression._tq_label  s'    ,,3$$== r-   c                     g rG   r^   rj   s    r,   r&  %WrapsColumnExpression._non_anon_label      r-   c                    > U R                   nUR                  (       d2  UR                  nU(       a  U$ [        US5      (       a  UR                  $ [
        [        U ]  $ )Nr  )r  r  r&  r   r  r6  r  )rJ   r  nalrP   s      r,   r  &WrapsColumnExpression._anon_name_label  sT    ,,
 ""%%C
011+++*DBBr-   c                     U R                   nUR                  nU(       a  U R                  US-   5      $ U R                  U5      $ )Nr  )r  r&  r  r  )rJ   r  r  r  s       r,   r  ,WrapsColumnExpression._dedupe_anon_label_idx  sA    ,,!!##C#I..11#66r-   c                 r   > U R                   nUR                  (       d  UR                  $ [        [        U ]
  $ rG   )r  r  r  r6  r  )rJ   r  rP   s     r,   r   WrapsColumnExpression._proxy_key  s/    ,,"">>!*D<<r-   r^   )r   r   r   r   r   r  r  r   r!  r&  r  r  r  r  r  ri   s   @r,   r  r    sx     $ $   F  C C7 = =r-   r  c                   ,   \ rS rSrSrSrS\R                  4S\R                  4S\R                  4S\R                  4S\R                  4/rS	rS
rS	rS
r\SS	\SSS	S	S	SSS	4S jrS	\4S jr\S 5       rS rS rS rSS jrS rS rS rS rS rSrg)r:   i  a  Represent a "bound expression".

:class:`.BindParameter` is invoked explicitly using the
:func:`.bindparam` function, as in::

    from sqlalchemy import bindparam

    stmt = select(users_table).\
                where(users_table.c.name == bindparam('username'))

Detailed discussion of how :class:`.BindParameter` is used is
at :func:`.bindparam`.

.. seealso::

    :func:`.bindparam`

r   r;   r(   callabler5   literal_executeFTNc                    U[         L a  U[         L =(       a    USL nU[         L a  SnUb  [        X5      nU(       aE  [        R                  [	        U 5      Ub  [        U[        5      (       d  UOSSS9U l        SU l        O9U(       a  Xl        O+[        R                  [	        U 5      S5      U l        SU l        U R                  U l        U=(       d    SU l	        X@l
        X l        Xpl        Xl        XPl        Xl        SU l        Xl        U(       a  SU l        UcL  U(       a  U(       a  US   nOUnUb  UR'                  X5      U l        g[*        R,                  " U5      U l        g[        U[(        5      (       a  U" 5       U l        gUR.                  (       a-  U(       a&  U(       a  US   nOUnUR1                  U5      U l        gX0l        g)a#  Produce a "bound expression".

The return value is an instance of :class:`.BindParameter`; this
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.

In SQLAlchemy, the :func:`.bindparam` construct has
the ability to carry along the actual value that will be ultimately
used at expression time.  In this way, it serves not just as
a "placeholder" for eventual population, but also as a means of
representing so-called "unsafe" values which should not be rendered
directly in a SQL statement, but rather should be passed along
to the :term:`DBAPI` as values which need to be correctly escaped
and potentially handled for type-safety.

When using :func:`.bindparam` explicitly, the use case is typically
one of traditional deferment of parameters; the :func:`.bindparam`
construct accepts a name which can then be referred to at execution
time::

    from sqlalchemy import bindparam

    stmt = select(users_table).\
                where(users_table.c.name == bindparam('username'))

The above statement, when rendered, will produce SQL similar to::

    SELECT id, name FROM user WHERE name = :username

In order to populate the value of ``:username`` above, the value
would typically be applied at execution time to a method
like :meth:`_engine.Connection.execute`::

    result = connection.execute(stmt, username='wendy')

Explicit use of :func:`.bindparam` is also common when producing
UPDATE or DELETE statements that are to be invoked multiple times,
where the WHERE criterion of the statement is to change on each
invocation, such as::

    stmt = (users_table.update().
            where(user_table.c.name == bindparam('username')).
            values(fullname=bindparam('fullname'))
            )

    connection.execute(
        stmt, [{"username": "wendy", "fullname": "Wendy Smith"},
               {"username": "jack", "fullname": "Jack Jones"},
               ]
    )

SQLAlchemy's Core expression system makes wide use of
:func:`.bindparam` in an implicit sense.   It is typical that Python
literal values passed to virtually all SQL expression functions are
coerced into fixed :func:`.bindparam` constructs.  For example, given
a comparison operation such as::

    expr = users_table.c.name == 'Wendy'

The above expression will produce a :class:`.BinaryExpression`
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::

    print(repr(expr.right))
    BindParameter('%(4327771088 name)s', 'Wendy', type_=String())

The expression above will render SQL such as::

    user.name = :name_1

Where the ``:name_1`` parameter name is an anonymous name.  The
actual string ``Wendy`` is not in the rendered string, but is carried
along where it is later used within statement execution.  If we
invoke a statement like the following::

    stmt = select(users_table).where(users_table.c.name == 'Wendy')
    result = connection.execute(stmt)

We would see SQL logging output as::

    SELECT "user".id, "user".name
    FROM "user"
    WHERE "user".name = %(name_1)s
    {'name_1': 'Wendy'}

Above, we see that ``Wendy`` is passed as a parameter to the database,
while the placeholder ``:name_1`` is rendered in the appropriate form
for the target database, in this case the PostgreSQL database.

Similarly, :func:`.bindparam` is invoked automatically when working
with :term:`CRUD` statements as far as the "VALUES" portion is
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::

    stmt = users_table.insert()
    result = connection.execute(stmt, name='Wendy')

The above will produce SQL output as::

    INSERT INTO "user" (name) VALUES (%(name)s)
    {'name': 'Wendy'}

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:`_engine.Connection.execute` method.

:param key:
  the key (e.g. the name) for this bind param.
  Will be used in the generated
  SQL statement for dialects that use named parameters.  This
  value may be modified when part of a compilation operation,
  if other :class:`BindParameter` objects exist with the same
  key, or if its length is too long and truncation is
  required.

:param value:
  Initial value for this bind param.  Will be used at statement
  execution time as the value for this parameter passed to the
  DBAPI, if no other value is indicated to the statement execution
  method for this particular parameter name.  Defaults to ``None``.

:param callable\_:
  A callable function that takes the place of "value".  The function
  will be called at statement execution time to determine the
  ultimate value.   Used for scenarios where the actual bind
  value cannot be determined at the point at which the clause
  construct is created, but embedded bind values are still desirable.

:param type\_:
  A :class:`.TypeEngine` class or instance representing an optional
  datatype for this :func:`.bindparam`.  If not passed, a type
  may be determined automatically for the bind, based on the given
  value; for example, trivial Python types such as ``str``,
  ``int``, ``bool``
  may result in the :class:`.String`, :class:`.Integer` or
  :class:`.Boolean` types being automatically selected.

  The type of a :func:`.bindparam` is significant especially in that
  the type will apply pre-processing to the value before it is
  passed to the database.  For example, a :func:`.bindparam` which
  refers to a datetime value, and is specified as holding the
  :class:`.DateTime` type, may apply conversion needed to the
  value (such as stringification on SQLite) before passing the value
  to the database.

:param unique:
  if True, the key name of this :class:`.BindParameter` will be
  modified if another :class:`.BindParameter` of the same name
  already has been located within the containing
  expression.  This flag is used generally by the internals
  when producing so-called "anonymous" bound expressions, it
  isn't generally applicable to explicitly-named :func:`.bindparam`
  constructs.

:param required:
  If ``True``, a value is required at execution time.  If not passed,
  it defaults to ``True`` if neither :paramref:`.bindparam.value`
  or :paramref:`.bindparam.callable` were passed.  If either of these
  parameters are present, then :paramref:`.bindparam.required`
  defaults to ``False``.

:param quote:
  True if this parameter name requires quoting and is not
  currently known as a SQLAlchemy reserved word; this currently
  only applies to the Oracle backend, where bound names must
  sometimes be quoted.

:param isoutparam:
  if True, the parameter should be treated like a stored procedure
  "OUT" parameter.  This applies to backends such as Oracle which
  support OUT parameters.

:param expanding:
  if True, this parameter will be treated as an "expanding" parameter
  at execution time; the parameter value is expected to be a sequence,
  rather than a scalar value, and the string SQL statement will
  be transformed on a per-execution basis to accommodate the sequence
  with a variable number of parameter slots passed to the DBAPI.
  This is to allow statement caching to be used in conjunction with
  an IN clause.

  .. seealso::

    :meth:`.ColumnOperators.in_`

    :ref:`baked_in` - with baked queries

  .. note:: The "expanding" feature does not support "executemany"-
     style parameter sets.

  .. versionadded:: 1.2

  .. versionchanged:: 1.3 the "expanding" bound parameter feature now
     supports empty lists.

:param literal_execute:
  if True, the bound parameter will be rendered in the compile phase
  with a special "POSTCOMPILE" token, and the SQLAlchemy compiler will
  render the final value of the parameter into the SQL statement at
  statement execution time, omitting the value from the parameter
  dictionary / list passed to DBAPI ``cursor.execute()``.  This
  produces a similar effect as that of using the ``literal_binds``,
  compilation flag,  however takes place as the statement is sent to
  the DBAPI ``cursor.execute()`` method, rather than when the statement
  is compiled.   The primary use of this
  capability is for rendering LIMIT / OFFSET clauses for database
  drivers that can't accommodate for bound parameters in these
  contexts, while allowing SQL constructs to be cacheable at the
  compilation level.

  .. versionadded:: 1.4 Added "post compile" bound parameters

    .. seealso::

        :ref:`change_4808`.

.. seealso::

    :ref:`tutorial_sending_parameters` - in the
    :ref:`unified_tutorial`

NparamTsanitize_keyr   )r   quoted_namer  r  r   r  r;   _key_is_anon_identifying_key	_orig_keyr8   r5   r  r9   r   rZ  	expand_opr  _is_crudcoerce_compared_valuer(   r	   _resolve_value_to_type_is_tuple_type_resolve_values_to_types)rJ   r;   r5   r"   r8   r   quote	callable_rZ  r9   r  rX  rY  r  check_values                  r,   __init__BindParameter.__init__  s   h v<9+<HF?Ec)C'664?:c;K+L+L ! 7 DH !%DH'66r$xIDH $D
 !% 
!$ 
 #
 . DM=U#Ah# ,-CC)	 %;;KH	t$$DI!!e#Ah#66{CDIIr-   c                     U R                  US9nXl        SUl        U[        La  UOU R                  Ul        UR
                  [        R                  L a  [        R                  " U5      Ul        U$ )zHReturn a copy of this :class:`.BindParameter` with the given value
set.
)r   N)	r   r5   r  r   r   r(   r	   r;  r  )rJ   r5   r   r   cloneds        r,   _with_valueBindParameter._with_value-  s]     ,7&.f&<($--;;(+++"99%@FKr-   c                 \    U R                   (       a  U R                  5       $ U R                  $ )zReturn the value of this bound parameter,
taking into account if the ``callable`` parameter
was set.

The ``callable`` value will be evaluated
and returned if present, else ``value``.

)r  r5   rj   s    r,   effective_valueBindParameter.effective_value9  s!     ====?"::r-   c                 b    U R                  U R                  U R                  U R                  SS9$ )a  Produce a copy of this bound parameter that will enable the
:paramref:`_sql.BindParameter.literal_execute` flag.

The :paramref:`_sql.BindParameter.literal_execute` flag will
have the effect of the parameter rendered in the compiled SQL
string using ``[POSTCOMPILE]`` form, which is a special form that
is converted to be a rendering of the literal value of the parameter
at SQL execution time.    The rationale is to support caching
of SQL statement strings that can embed per-statement literal values,
such as LIMIT and OFFSET parameters, in the final SQL string that
is passed to the DBAPI.   Dialects in particular may want to use
this method within custom compilation schemes.

.. versionadded:: 1.4.5

.. seealso::

    :ref:`engine_thirdparty_caching`

T)r"   r  )rP   r;   r5   r(   rj   s    r,   render_literal_execute$BindParameter.render_literal_executeH  s2    * ~~HHJJ)) 	  
 	
r-   c                 T    U R                   UL a  U R                  5       nXl         U$ U $ rG   )r  r   )rJ   r_   r`   r   s       r,   ra   BindParameter._negate_in_binaryd  s(    >>[(;;=D'NKKr-   c                 <    [         R                  U 5      nXl        U$ rG   )rC   r   r(   )rJ   r"   rX   s      r,   rf   'BindParameter._with_binary_element_typel  s      &r-   c                    [         R                  " U 40 UD6nUR                  R                  U R                  5        U(       dG  U R                  (       a6  [
        R                  [        U5      UR                  =(       d    SSS9Ul	        U$ )Nr  Tr  )
rC   r   rr   r   r8   r  r  r   r  r;   )rJ   r   rV   rX   s       r,   r   BindParameter._cloneq  sl      ,, 	
T--.$331q{{-gD 4 AE r-   c                    U R                   R                  R                  SS5      nU(       d  Ub	  SU[        '   g [	        U 5      nXA;   a  X   U R                   4$ [        UR                  5      =X'   nU=R                  S-  sl        Ub  UR                  U 5        UU R                   U R                  R                  U R                  (       a  U R                  U-  U R                  4$ U R                  U R                  4$ )Ninherit_cacheFTr   )rP   rR   r   r   r   r   indexappendr(   _static_cache_keyr  r;   r  )rJ   anon_map
bindparams_gen_cache_okidselfid_s         r,   _gen_cache_keyBindParameter._gen_cache_key  s    //33OUK#%)"D$dnn55 &)%88HsNNaN!d# NNII''#'#4#4DHHx  
 	
 ;?((  
 	
r-   c                     U R                   (       d>  SU l         [        R                  [        U 5      U R                  =(       d    SSS9U l        g g )NTr  r  )r8   r  r  r   r  r;   rj   s    r,   r    BindParameter._convert_to_unique  s@    {{DK'664$..3G$ 7 DH r-   c                     U R                   R                  5       nU R                  nU R                  (       a  U R                  5       nSUS'   X!S'   U$ )z4execute a deferred value for serialization purposes.Nr  r5   )rR   rS   r5   r  )rJ   r{   rZ   s      r,   r|   BindParameter.__getstate__  sF     MM JJ==A AjM'
r-   c                     UR                  SS5      (       a1  [        R                  [        U 5      UR                  SS5      SS9US'   U R                  R                  U5        g )Nr8   Fr  r  Tr  r;   )r   r  r  r   rR   r   rG  s     r,   rI  BindParameter.__setstate__  sV    99Xu%%+::4%))K9 ; E%L 	U#r-   c                     U R                   R                  < SU R                  < SU R                  < SU R                  < S3$ )N(, z, type_=))rP   r   r;   r5   r(   rj   s    r,   r   BindParameter.__repr__  s.    NN##HHJJII	
 	
r-   )r  r  r  r  r  r  rZ  r9   r;   r  r   r(   r8   r5   r   ) r   r   r   r   r   r   r   dp_anon_namedp_typedp_plain_dictdp_plain_obj
dp_boolean_traverse_internalsr  r  r  r  r   r  r  r  r  r  ra   rf   r   r  r   r|   rI  r   r  r^   r-   r,   r:   r:     s    & !N 
!../	"**+	&445	#001	-889 HL M
 "||	 /4f 
  
8
"
8	$
r-   r:   c                   @    \ rS rSrSrSrS\R                  4/rS r	Sr
g)
TypeClausei  zLHandle a type keyword in a SQL statement.

Used by the ``Case`` statement.


typeclauser(   c                     Xl         g rG   r(   re   s     r,   r  TypeClause.__init__  s    	r-   r+  N)r   r   r   r   r   r   r   r"  r&  r  r  r^   r-   r,   r(  r(    s(     "N"$5$=$=>?r-   r(  c                      \ rS rSrSrSrS\R                  4S\R                  4/r	Sr
Sr\R                  " S\R                  5      r\R"                  R%                  S\05      rS	rS	rS
rS r\S 5       rS=rrS	r\S 5       rSS jr\\ " SSS5      \!RD                  " SS9SS j5       5       5       r#\$S 5       r%\!RL                  " S5      S 5       r'\S 5       r(\S 5       r)SS jr*Sr+g)
TextClausei  aX  Represent a literal SQL text fragment.

E.g.::

    from sqlalchemy import text

    t = text("SELECT * FROM users")
    result = connection.execute(t)


The :class:`_expression.TextClause` construct is produced using the
:func:`_expression.text`
function; see that function for full documentation.

.. seealso::

    :func:`_expression.text`


textclause_bindparamstextTz(?<![:\w\x5c]):(\w+)(?!:)
autocommitFr^   c                     [        X5      $ rG   )r)  r|  s     r,   __and__TextClause.__and__  s    D  r-   c                     U 4$ rG   r^   rj   s    r,   rb  TextClause._select_iterable	  rd  r-   Nc                      U R                   S:H  $ N*)r1  rj   s    r,   r  TextClause._is_star  s    yyCr-   c                 n   ^  UT l         0 T l        U 4S jnT R                  R                  X15      T l        g )Nc                    > [        U R                  S5      5      TR                  U R                  S5      '   SU R                  S5      -  $ )Nr   z:%s)r:   groupr0  )mrJ   s    r,   repl!TextClause.__init__.<locals>.repl  s;    +8+DDQWWQZ(1771:%%r-   )_bindr0  _bind_params_regexsubr1  )rJ   r1  r   r@  s   `   r,   r  TextClause.__init__  s1    
	& ++//;	r-   z:func:`.text`z:paramref:`.text.text`)z2.0z\The :paramref:`_sql.text.bind` argument is deprecated and will be removed in SQLAlchemy 2.0.r   c                     [        XS9$ )a  Construct a new :class:`_expression.TextClause` clause,
representing
a textual SQL string directly.

E.g.::

    from sqlalchemy import text

    t = text("SELECT * FROM users")
    result = connection.execute(t)

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
SQLAlchemy type constructs to play a role when executing
a statement that is specified literally.  The construct can also
be provided with a ``.c`` collection of column elements, allowing
it to be embedded in other SQL expression constructs as a subquery.

Bind parameters are specified by name, using the format ``:name``.
E.g.::

    t = text("SELECT * FROM users WHERE id=:user_id")
    result = connection.execute(t, user_id=12)

For SQL statements where a colon is required verbatim, as within
an inline string, use a backslash to escape::

    t = text("SELECT * FROM users WHERE name='\:username'")

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:`_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").\
            bindparams(user_id=7).\
            columns(id=Integer, name=String)

    for id, name in connection.execute(t):
        print(id, name)

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:`_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:`_expression.text`
construct that should be subject to "autocommit"
can be set explicitly so using the
:paramref:`.Connection.execution_options.autocommit` option::

    t = text("EXEC my_procedural_thing()").\
            execution_options(autocommit=True)

.. deprecated:: 1.4  The "autocommit" execution option is deprecated
   and will be removed in SQLAlchemy 2.0.  See
   :ref:`migration_20_autocommit` for discussion.

:param text:
  the text of the SQL statement to be created.  Use ``:<param>``
  to specify bind parameters; they will be compiled to their
  engine-specific format.

:param bind:
  an optional connection or engine to be used for this text query.

.. seealso::

    :ref:`tutorial_select_arbitrary_text`


rF  )r.  )clsr1  r   s      r,   _create_textTextClause._create_text#  s    D $**r-   c                    U R                   R                  5       =U l         nU H   n X4R                     nXCUR                  '   M"     UR                  5        H  u  px X7   nUR                  USS9X7'   M     g! [         aA  n[        R
                  " [        R                  " SUR                  -  5      US9   SnAM  SnAff = f! [         a7  n[        R
                  " [        R                  " SU-  5      US9   SnAM  SnAff = f)ay  Establish the values and/or types of bound parameters within
this :class:`_expression.TextClause` construct.

Given a text construct such as::

    from sqlalchemy import text
    stmt = text("SELECT id, name FROM user WHERE name=:name "
                "AND timestamp=:timestamp")

the :meth:`_expression.TextClause.bindparams`
method can be used to establish
the initial value of ``:name`` and ``:timestamp``,
using simple keyword arguments::

    stmt = stmt.bindparams(name='jack',
                timestamp=datetime.datetime(2012, 10, 8, 15, 12, 5))

Where above, new :class:`.BindParameter` objects
will be generated with the names ``name`` and ``timestamp``, and
values of ``jack`` and ``datetime.datetime(2012, 10, 8, 15, 12, 5)``,
respectively.  The types will be
inferred from the values given, in this case :class:`.String` and
:class:`.DateTime`.

When specific typing behavior is needed, the positional ``*binds``
argument can be used in which to specify :func:`.bindparam` constructs
directly.  These constructs must include at least the ``key``
argument, then an optional value and type::

    from sqlalchemy import bindparam
    stmt = stmt.bindparams(
                    bindparam('name', value='jack', type_=String),
                    bindparam('timestamp', type_=DateTime)
                )

Above, we specified the type of :class:`.DateTime` for the
``timestamp`` bind, and the type of :class:`.String` for the ``name``
bind.  In the case of ``name`` we also set the default value of
``"jack"``.

Additional bound parameters can be supplied at statement execution
time, e.g.::

    result = connection.execute(stmt,
                timestamp=datetime.datetime(2012, 10, 8, 15, 12, 5))

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:`_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 "
                "AND timestamp=:timestamp")
    stmt = stmt.bindparams(
        bindparam('name', type_=String),
        bindparam('timestamp', type_=DateTime)
    )
    stmt = stmt.bindparams(
        name='jack',
        timestamp=datetime.datetime(2012, 10, 8, 15, 12, 5)
    )

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:`_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::

    stmt1 = text("select id from table where name=:name").bindparams(
        bindparam("name", value='name1', unique=True)
    )
    stmt2 = text("select id from table where name=:name").bindparams(
        bindparam("name", value='name2', unique=True)
    )

    union = union_all(
        stmt1.columns(column("id")),
        stmt2.columns(column("id"))
    )

The above statement will render as::

    select id from table where name=:name_1
    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:`_expression.text`
   constructs.

z?This text() construct doesn't define a bound parameter named %rr?  NF)r   )
r0  rS   r  KeyErrorr   rB  r   r   rT   r  )	rJ   bindsnames_to_values
new_paramsr   existingrC  r;   r5   s	            r,   r  TextClause.bindparams  s   H )-(8(8(=(=(??:D6 &nn5 268--. " *//1JCN%? #+"6"6uu"6"M
 2  %%359^^D %(   %%3589 %( s/   A9C9
C6B??C
D,DDzsqlalchemy.sql.selectablec           	         [         R                  R                  nU Vs/ s HD  nUR                  U;   a/  [	        UR                  UR                  UR                  5      5      OUPMF     nnUR                  5        VVs/ s H  u  pg[	        Xg5      PM     nnnUR                  U XX-   [        U5      =(       a    U(       + S9$ s  snf s  snnf )a!  Turn this :class:`_expression.TextClause` object into a
:class:`_expression.TextualSelect`
object that serves the same role as a SELECT
statement.

The :class:`_expression.TextualSelect` is part of the
:class:`_expression.SelectBase`
hierarchy and can be embedded into another statement by using the
: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
textual SELECT statement and the SQL expression language concept
of a "selectable"::

    from sqlalchemy.sql import column, text

    stmt = text("SELECT id, name FROM some_table")
    stmt = stmt.columns(column('id'), column('name')).subquery('st')

    stmt = select(mytable).\
            select_from(
                mytable.join(stmt, mytable.c.name == stmt.c.name)
            ).where(stmt.c.id > 5)

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:`_expression.TextualSelect.selected_columns` column collection,
which then
become part of the :attr:`.Subquery.c` collection after
:meth:`_expression.TextualSelect.subquery` is invoked.

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.
This is often needed for types such as date or boolean types, as well
as for unicode processing on some dialect configurations::

    stmt = text("SELECT id, name, timestamp FROM some_table")
    stmt = stmt.columns(
                column('id', Integer),
                column('name', Unicode),
                column('timestamp', DateTime)
            )

    for id, name, timestamp in connection.execute(stmt):
        print(id, name, timestamp)

As a shortcut to the above syntax, keyword arguments referring to
types alone may be used, if only type conversion is needed::

    stmt = text("SELECT id, name, timestamp FROM some_table")
    stmt = stmt.columns(
                id=Integer,
                name=Unicode,
                timestamp=DateTime
            )

    for id, name, timestamp in connection.execute(stmt):
        print(id, name, timestamp)

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:`_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::

    stmt = text("SELECT users.id, addresses.id, users.id, "
         "users.name, addresses.email_address AS email "
         "FROM users JOIN addresses ON users.id=addresses.user_id "
         "WHERE users.id = 1").columns(
            User.id,
            Address.id,
            Address.user_id,
            User.name,
            Address.email_address
         )

    query = session.query(User).from_statement(stmt).options(
        contains_eager(User.addresses))

.. 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:`_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:`_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.

:param \**types: A mapping of string names to :class:`.TypeEngine`
 type objects indicating the datatypes to use for names that are
 SELECTed from the textual string.  Prefer to use the ``*cols``
 argument as it also indicates positional ordering.

)
positional)	r   r   sql_selectabler;   r  rz   rT   TextualSelectr   )	rJ   colstypesr  colpositional_input_colsr;   r"   keyed_input_colss	            r,   r  TextClause.columns  s    l ^^22

 	!
  ww% %))CGG"45 	 	 !
 8={{}
7DL$} 	 
 ''!412K;K7K ( 
 	
!

s   AC?Cc                 "    [         R                  $ rG   r:  rj   s    r,   r(   TextClause.type  r=  r-   c                 8    U R                   R                  U 5      $ rG   )r(   rA  rj   s    r,   rD  TextClause.comparator  s    yy++D11r-   c                 B    U[         R                  L a  [        U 5      $ U $ rG   )r   in_opr3  r   s     r,   r   TextClause.self_group  s    ioo%D>!Kr-   )rB  r0  r1  rG   ),r   r   r   r   r   r   r   dp_string_clauseelement_dict	dp_stringr&  r  r  rer   UNICODErC  r   _execution_optionsunionr   r  r  _hide_fromsr4  r  rb  r;   r!  r  r  r  classmethodr   r   deprecated_paramsrI  r   r  r  r  r(   rD  r   r  r^   r-   r,   r.  r.    sx   ( "N 
)FFG	",,-
 OK$@"**M#66<<	'( #&+#K!  
 C&    
< V_6NO	
Y+ P Y+v BN BNH 
45D
 6D
L ! ! 2 2r-   r.  c                   T    \ rS rSrSrSr/ r\R                  S 5       r	\
S 5       rSrg)Nulli  zzRepresent the NULL keyword in a SQL statement.

:class:`.Null` is accessed as a constant via the
:func:`.null` function.

nullc                 "    [         R                  $ rG   r:  rj   s    r,   r(   	Null.type  r=  r-   c                     [        5       $ )z+Return a constant :class:`.Null` construct.)rm  rH  s    r,   	_instanceNull._instance  s     vr-   r^   N)r   r   r   r   r   r   r&  r   r  r(   rj  rs  r  r^   r-   r,   rm  rm    s@     N	! !  r-   rm  c                   Z    \ rS rSrSrSr/ r\R                  S 5       r	S r
\S 5       rSrg)	False_i  zRepresent the ``false`` keyword, or equivalent, in a SQL statement.

:class:`.False_` is accessed as a constant via the
:func:`.false` function.

falsec                 "    [         R                  $ rG   r	   r-  rj   s    r,   r(   False_.type      ###r-   c                     [        5       $ rG   True_rj   s    r,   r   False_._negate  s	    wr-   c                     [        5       $ )ai  Return a :class:`.False_` construct.

E.g.::

    >>> from sqlalchemy import false
    >>> print(select(t.c.x).where(false()))
    SELECT x FROM t WHERE false

A backend which does not support true/false constants will render as
an expression against 1 or 0::

    >>> print(select(t.c.x).where(false()))
    SELECT x FROM t WHERE 0 = 1

The :func:`.true` and :func:`.false` constants also feature
"short circuit" operation within an :func:`.and_` or :func:`.or_`
conjunction::

    >>> print(select(t.c.x).where(or_(t.c.x > 5, true())))
    SELECT x FROM t WHERE true

    >>> print(select(t.c.x).where(and_(t.c.x > 5, false())))
    SELECT x FROM t WHERE false

.. versionchanged:: 0.9 :func:`.true` and :func:`.false` feature
   better integrated behavior within conjunctions and on dialects
   that don't support true/false constants.

.. seealso::

    :func:`.true`

rv  rr  s    r,   rs  False_._instance  s    H xr-   r^   N)r   r   r   r   r   r   r&  r   r  r(   r   rj  rs  r  r^   r-   r,   rv  rv    sE     N	$ $ # #r-   rv  c                   j    \ rS rSrSrSr/ r\R                  S 5       r	S r
\S 5       r\S 5       rSrg	)
r~  i  zRepresent the ``true`` keyword, or equivalent, in a SQL statement.

:class:`.True_` is accessed as a constant via the
:func:`.true` function.

truec                 "    [         R                  $ rG   ry  rj   s    r,   r(   
True_.type	  r{  r-   c                     [        5       $ rG   r  rj   s    r,   r   True_._negate	  s	    xr-   c                 ,    Uc  U R                  5       $ U$ rG   )rs  )rH  r   s     r,   _ifnoneTrue_._ifnone	  s    ===?"Lr-   c                     [        5       $ )an  Return a constant :class:`.True_` construct.

E.g.::

    >>> from sqlalchemy import true
    >>> print(select(t.c.x).where(true()))
    SELECT x FROM t WHERE true

A backend which does not support true/false constants will render as
an expression against 1 or 0::

    >>> print(select(t.c.x).where(true()))
    SELECT x FROM t WHERE 1 = 1

The :func:`.true` and :func:`.false` constants also feature
"short circuit" operation within an :func:`.and_` or :func:`.or_`
conjunction::

    >>> print(select(t.c.x).where(or_(t.c.x > 5, true())))
    SELECT x FROM t WHERE true

    >>> print(select(t.c.x).where(and_(t.c.x > 5, false())))
    SELECT x FROM t WHERE false

.. versionchanged:: 0.9 :func:`.true` and :func:`.false` feature
   better integrated behavior within conjunctions and on dialects
   that don't support true/false constants.

.. seealso::

    :func:`.false`

r}  rr  s    r,   rs  True_._instance	  s    H wr-   r^   N)r   r   r   r   r   r   r&  r   r  r(   r   rj  r  rs  r  r^   r-   r,   r~  r~    sY     N	$ $   # #r-   r~  c                       \ rS rSrSrSrSrS\R                  4S\R                  4/r
S r\SS	 j5       rS
 rS r\S 5       rS r\S 5       rSS jrSrg)
ClauseListi<	  zrDescribe a list of clauses, separated by an operator.

By default, is comma-separated, such as a column listing.


clauselistTclausesr   c           	         UR                  S[        R                  5      U l        UR                  SS5      U l        UR                  SS5      U l        UR                  SS5      (       a  [        R                  " U5      nUR                  S[        R                  5      =U l
        nU R
                  (       aC  U Vs/ s H/  n[        R                  " X4U S9R                  U R                  S	9PM1     snU l        O+U Vs/ s H  n[        R                  " X4U S9PM     snU l        [        R                  " U R                  5      U l        g s  snf s  snf )
Nr   r>  Tgroup_contents_flatten_sub_clausesF_literal_as_text_roleapply_propagate_attrsr   )rz   r   comma_opr   r>  r  r   flatten_iteratorr   WhereHavingRole_text_converter_roler   r#   r   r  
is_booleanr  )rJ   r  r   text_converter_roler@   s        r,   r  ClauseList.__init__R	  s3   

:y/A/ABZZ.
$jj)94@::,e44++G4G:@**#U%:%:;
 	
!$7 
 &	 &F   't*T]]*34 &	DL &	 &F   't &	DL '0&:&:4==&I#s   =6E ENc                 ~    U R                  U 5      nU(       a  UO/ Ul        SUl        Xl        SUl        SUl        U$ )NTF)rQ   r  r>  r   r  r  rH  r   r  rJ   s       r,   _construct_rawClauseList._construct_rawk	  s<    {{3")wr
 "&+#r-   c                 ,    [        U R                  5      $ rG   )iterr  rj   s    r,   __iter__ClauseList.__iter__u	  s    DLL!!r-   c                 ,    [        U R                  5      $ rG   )r   r  rj   s    r,   __len__ClauseList.__len__x	  s    4<<  r-   c                     [         R                  R                  U R                   Vs/ s H  oR                  PM     sn5      $ s  snf rG   )	itertoolschainfrom_iterabler  rb  )rJ   elems     r,   rb  ClauseList._select_iterable{	  s6    ,,/3||<|t""|<
 	
<s   Ac                 >   U R                   (       aR  U R                  R                  [        R                  " U R
                  U5      R                  U R                  S95        g U R                  R                  [        R                  " U R
                  U5      5        g Nr   )r  r  r  r   r#   r  r   r   )rJ   r@   s     r,   r  ClauseList.append	  su    LL  !:!:FCNN MM O  LL  !:!:FCr-   c                     [        [        R                  " U R                   Vs/ s H  oR                  PM     sn6 5      $ s  snf rG   )listr  r  r  r   rJ   rX   s     r,   r   ClauseList._from_objects	  s.    IOOt||%L|!oo|%LMNN%Ls   Ac                     U R                   (       a1  [        R                  " U R                  U5      (       a  [	        U 5      $ U $ rG   )r>  r   is_precedentr   r3  r   s     r,   r   ClauseList.self_group	  s.    ::)00HHD>!Kr-   )r  r  r  r>  r  r   rG   )r   r   r   r   r   r   r	  r   dp_clauseelement_listdp_operatorr&  r  rj  r  r  r  r  rb  r  r   r   r  r^   r-   r,   r  r  <	  s     "NO 
%;;<	&223
J2  "! 
 


 O Or-   r  c                      ^  \ rS rSrSrSrS r\S 5       r\S 5       r	\S 5       r
\SS j5       r\S	 5       r\S
 5       r\S 5       rSU 4S jjrS rSrU =r$ )BooleanClauseListi	  r  Tc                     [        S5      e)Nz+BooleanClauseList has a private constructorr  )rJ   argrV   s      r,   r  BooleanClauseList.__init__	  s    !9
 	
r-   c                    S n/ n[         R                  nSnU H5  n	XL a  U	nM  XL a  U	/nSn  O#U(       d  SnOUnSnUR                  U	5        M7     U(       d  Ub  U/nSnX V
s/ s H  oR                  US9PM     sn
4$ s  sn
f )Nr   r   r   r   )r   r+  r  r   )rH  r   continue_onskip_onr  has_continue_onconvert_clausesr   lccr@   rX   s              r,   _process_clauses_for_boolean.BooleanClauseList._process_clauses_for_boolean	  s     ##F$ #)" $*(C&G C&&v.) , ?#>./OCOLOq\\'\2OLLLLs   %Bc                    U R                  UUU[        R                  " U5       Vs/ s H(  n[        R                  " [
        R                  U5      PM*     sn5      u  pxUS:  a  U R                  X5      $ US:X  a  US   $ [        R                  " SUR                  U[        R                  L a  SOSS.-  SS9  U R                  U5      $ s  snf )	Nr   r   zInvoking %(name)s() without arguments is deprecated, and will be disallowed in a future release.   For an empty %(name)s() construct, use %(name)s(%(continue_on)s, *args).TrueFalse)r$  r  r  )version)r  r   coerce_generator_argr   r#   r   r  r  warn_deprecatedr   r~  
_singleton)	rH  r   r  r  r  rV   r@   r  r  s	            r,   
_constructBooleanClauseList._construct	  s    "?? #77@@F   !6!6?@	 
 7 %%h@@AX #1%%
   N %--"e&6&66 $* 	  %%h//=s   /Cc                     [         R                  [        R                  [        R                  pCnU R                  UUUU5      u  pVUS:  a  U R                  X&5      $ US:X  a  US   $ g )Nr   r   )r   r)  r~  r  rv  r  r  )rH  r  r   r  r  r  r  s          r,   _construct_for_whereclause,BooleanClauseList._construct_for_whereclause	  sx     NN  '  #??	 
 7 %%h@@AX #1%%r-   c                     U R                  U 5      nU(       a  UO/ Ul        SUl        Xl        SUl        [
        R                  Ul        SUl        U$ NT)	rQ   r  r>  r   r  r	   r-  r(   r  r  s       r,   r   BooleanClauseList._construct_raw
  sI    {{3")wr
 "((	&*#r-   c                     U R                   " [        R                  [        R                  [
        R                  /UQ76 $ )a  Produce a conjunction of expressions joined by ``AND``.

E.g.::

    from sqlalchemy import and_

    stmt = select(users_table).where(
                    and_(
                        users_table.c.name == 'wendy',
                        users_table.c.enrolled == True
                    )
                )

The :func:`.and_` conjunction is also available using the
Python ``&`` operator (though note that compound expressions
need to be parenthesized in order to function with Python
operator precedence behavior)::

    stmt = select(users_table).where(
                    (users_table.c.name == 'wendy') &
                    (users_table.c.enrolled == True)
                )

The :func:`.and_` operation is also implicit in some cases;
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_`::

    stmt = select(users_table).\
            where(users_table.c.name == 'wendy').\
            where(users_table.c.enrolled == True)

The :func:`.and_` construct must be given at least one positional
argument in order to be valid; a :func:`.and_` construct with no
arguments is ambiguous.   To produce an "empty" or dynamically
generated :func:`.and_`  expression, from a given list of expressions,
a "default" element of ``True`` should be specified::

    criteria = and_(True, *expressions)

The above expression will compile to SQL as the expression ``true``
or ``1 = 1``, depending on backend, if no other expressions are
present.  If expressions are present, then the ``True`` value is
ignored as it does not affect the outcome of an AND expression that
has other elements.

.. deprecated:: 1.4  The :func:`.and_` element now requires that at
   least one argument is passed; creating the :func:`.and_` construct
   with no arguments is deprecated, and will emit a deprecation warning
   while continuing to produce a blank SQL string.

.. seealso::

    :func:`.or_`

)r  r   r)  r~  r  rv  rH  r  s     r,   r)  BooleanClauseList.and_
  s5    v ~~NNE,,f.?.?
BI
 	
r-   c                     U R                   " [        R                  [        R                  [
        R                  /UQ76 $ )aV  Produce a conjunction of expressions joined by ``OR``.

E.g.::

    from sqlalchemy import or_

    stmt = select(users_table).where(
                    or_(
                        users_table.c.name == 'wendy',
                        users_table.c.name == 'jack'
                    )
                )

The :func:`.or_` conjunction is also available using the
Python ``|`` operator (though note that compound expressions
need to be parenthesized in order to function with Python
operator precedence behavior)::

    stmt = select(users_table).where(
                    (users_table.c.name == 'wendy') |
                    (users_table.c.name == 'jack')
                )

The :func:`.or_` construct must be given at least one positional
argument in order to be valid; a :func:`.or_` construct with no
arguments is ambiguous.   To produce an "empty" or dynamically
generated :func:`.or_`  expression, from a given list of expressions,
a "default" element of ``False`` should be specified::

    or_criteria = or_(False, *expressions)

The above expression will compile to SQL as the expression ``false``
or ``0 = 1``, depending on backend, if no other expressions are
present.  If expressions are present, then the ``False`` value is
ignored as it does not affect the outcome of an OR expression which
has other elements.

.. deprecated:: 1.4  The :func:`.or_` element now requires that at
   least one argument is passed; creating the :func:`.or_` construct
   with no arguments is deprecated, and will emit a deprecation warning
   while continuing to produce a blank SQL string.

.. seealso::

    :func:`.and_`

)r  r   r*  rv  r  r~  r  s     r,   r*  BooleanClauseList.or_R
  s5    b ~~MM6,,e.>.>
AH
 	
r-   c                     U 4$ rG   r^   rj   s    r,   rb  "BooleanClauseList._select_iterable
  rd  r-   c                 L   > U R                   (       d  U $ [        [        U ]  US9$ r  )r  r6  r  r   )rJ   r   rP   s     r,   r   BooleanClauseList.self_group
  s%    ||K*D<W<MMr-   c                 ,    [         R                  U 5      $ rG   )r  r   rj   s    r,   r   BooleanClauseList._negate
  s    !!$''r-   )r  r  r>  r  r   r(   rG   )r   r   r   r   r   r  r  rj  r  r  r  r  r)  r*  r  rb  r   r   r  r  ri   s   @r,   r  r  	  s    !NM

 $M $ML #0 #0J  2   <
 <
| 2
 2
h  N( (r-   r  c                      ^  \ rS rSrSrSr\R                  / -   r\R                  " S5      U 4S j5       r
\S 5       rS
S jrSS jrS	rU =r$ )Tuplei
  zRepresent a SQL tuple.r   zsqlalchemy.sql.sqltypesc           
        > [         R                  R                  nUR                  SS5      nUc6  U Vs/ s H(  n[        R
                  " [        R                  U5      PM*     nnO[        U5      [        U5      :w  a$  [        R                  " S[        U5      U4-  5      e[        XA5       VVs/ s H<  u  pe[        R
                  " [        R                  UUR                  (       d  UOSS9PM>     nnnUR                  " U Vs/ s H  owR                  PM     sn6 U l        [        [         U ]F  " U0 UD6  gs  snf s  snnf s  snf )aD  Return a :class:`.Tuple`.

Main usage is to produce a composite IN construct using
:meth:`.ColumnOperators.in_` ::

    from sqlalchemy import tuple_

    tuple_(table.c.col1, table.c.col2).in_(
        [(1, 2), (5, 12), (10, 19)]
    )

.. versionchanged:: 1.3.6 Added support for SQLite IN tuples.

.. warning::

    The composite IN construct is not supported by all backends, and is
    currently known to work on PostgreSQL, MySQL, and SQLite.
    Unsupported backends will raise a subclass of
    :class:`~sqlalchemy.exc.DBAPIError` when such an expression is
    invoked.

rW  Nz*Wrong number of elements for %d-tuple: %r r!   )r   r   sql_sqltypesrz   r   r#   r   r$   r   r   r   zip_isnull	TupleTyper(   r6  r  r  )	rJ   r  rV   sqltypesrW  rX   typr  rP   s	           r,   r  Tuple.__init__
  s1   0 >>..w%= ! A   !<!<a@   G
 5zS\)''@5z7+,  "%1 2FC   //%([[#d
 2   &&W(EWcW(EF	eT#W33) )Fs   /D:1AD?Ec                     U 4$ rG   r^   rj   s    r,   rb  Tuple._select_iterable
  rd  r-   c                     U(       a  [        S UUSSU R                  S9$ [        [        X R                  R                  5       VVs/ s H  u  pV[        S UUUSUS9PM     snn6 $ s  snnf )NT)r5   rX  r8   rZ  r"   )rX  rY  r8   r"   )r:   r(   r  r  rW  )rJ   r   r\  r"   rZ  ocompared_to_types          r,   r]  Tuple._bind_param
  s     &.ii   033		/H
 0I+ ".6*:## 0I
 
s   A&
c                     U $ rG   r^   r   s     r,   r   Tuple.self_group
      r-   r+  r   rG   )r   r   r   r   r   r   r  r&  r   r  r  r  rb  r]  r   r  r  ri   s   @r,   r  r  
  s^     N$882=	23/4 4/4b  2 r-   r  c                       \ rS rSrSrSrS\R                  4S\R                  4S\R                  4/r	S r
\S 5       rS	rg
)Casei
  a  Represent a ``CASE`` expression.

:class:`.Case` is produced using the :func:`.case` factory function,
as in::

    from sqlalchemy import case

    stmt = select(users_table).                    where(
                    case(
                        (users_table.c.name == 'wendy', 'W'),
                        (users_table.c.name == 'jack', 'J'),
                        else_='E'
                    )
                )

Details on :class:`.Case` usage is at :func:`.case`.

.. seealso::

    :func:`.case`

caser5   whenselse_c           
         SU;   a(  [         R                  " S5        UR                  S5      4n[        R                  " SSU5      n [         R
                  " U5      nUR                  SS5      nU VVs/ s H\  u  pE[        R                  " [        R                  UU S9R                  5       [        R                  " [        R                  U5      4PM^     nnnU(       a  [        US   5      S   R                  nOSnUc  SU l        O*[        R                  " [        R                  U5      U l        Xpl        X`l        UR                  SS5      nUb+  [        R                  " [        R                  U5      U l        OSU l        U(       a&  [        S	S
R!                  [#        U5      5      -  5      eg! [         a     GNef = fs  snnf )a  Produce a ``CASE`` expression.

The ``CASE`` construct in SQL is a conditional object that
acts somewhat analogously to an "if/then" construct in other
languages.  It returns an instance of :class:`.Case`.

:func:`.case` in its usual form is passed a series of "when"
constructs, that is, a list of conditions and results as tuples::

    from sqlalchemy import case

    stmt = select(users_table).\
                where(
                    case(
                        (users_table.c.name == 'wendy', 'W'),
                        (users_table.c.name == 'jack', 'J'),
                        else_='E'
                    )
                )

The above statement will produce SQL resembling::

    SELECT id, name FROM user
    WHERE CASE
        WHEN (name = :name_1) THEN :param_1
        WHEN (name = :name_2) THEN :param_2
        ELSE :param_3
    END

When simple equality expressions of several values against a single
parent column are needed, :func:`.case` also has a "shorthand" format
used via the
:paramref:`.case.value` parameter, which is passed a column
expression to be compared.  In this form, the :paramref:`.case.whens`
parameter is passed as a dictionary containing expressions to be
compared against keyed to result expressions.  The statement below is
equivalent to the preceding statement::

    stmt = select(users_table).\
                where(
                    case(
                        {"wendy": "W", "jack": "J"},
                        value=users_table.c.name,
                        else_='E'
                    )
                )

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:`_expression.ColumnElement` constructs,
are accepted
as well.  To coerce a literal string expression into a constant
expression rendered inline, use the :func:`_expression.literal_column`
construct,
as in::

    from sqlalchemy import case, literal_column

    case(
        (
            orderline.c.qty > 100,
            literal_column("'greaterthan100'")
        ),
        (
            orderline.c.qty > 10,
            literal_column("'greaterthan10'")
        ),
        else_=literal_column("'lessthan10'")
    )

The above will render the given constants without using bound
parameters for the result values (but still for the comparison
values), as in::

    CASE
        WHEN (orderline.qty > :qty_1) THEN 'greaterthan100'
        WHEN (orderline.qty > :qty_2) THEN 'greaterthan10'
        ELSE 'lessthan10'
    END

:param \*whens: The criteria to be compared against,
 :paramref:`.case.whens` accepts two different forms, based on
 whether or not :paramref:`.case.value` is used.

 .. versionchanged:: 1.4 the :func:`_sql.case`
    function now accepts the series of WHEN conditions positionally;
    passing the expressions within a list is deprecated.

 In the first form, it accepts a list of 2-tuples; each 2-tuple
 consists of ``(<sql expression>, <value>)``, where the SQL
 expression is a boolean expression and "value" is a resulting value,
 e.g.::

    case(
        (users_table.c.name == 'wendy', 'W'),
        (users_table.c.name == 'jack', 'J')
    )

 In the second form, it accepts a Python dictionary of comparison
 values mapped to a resulting value; this form requires
 :paramref:`.case.value` to be present, and values will be compared
 using the ``==`` operator, e.g.::

    case(
        {"wendy": "W", "jack": "J"},
        value=users_table.c.name
    )

:param value: An optional SQL expression which will be used as a
  fixed "comparison point" for candidate values within a dictionary
  passed to :paramref:`.case.whens`.

:param else\_: An optional SQL expression which will be the evaluated
  result of the ``CASE`` construct if all expressions within
  :paramref:`.case.whens` evaluate to false.  When omitted, most
  databases will produce a result of NULL if none of the "when"
  expressions evaluate to true.


r  zdThe "whens" argument to case() is now passed using positional style only, not as a keyword argument.r  r5   Nr  r  zunknown arguments: %sr  )r   warn_deprecated_20rz   r   !_expression_collection_was_a_listdictlike_iteritemsr   r#   r   r$   r   r  r(   r5   r  r  joinsorted)	rJ   r  rV   r5   rX   rwhenlistr"   r  s	            r,   r  Case.__init__  s   v b=##D VVG_&E;;VU
	++E2E w%  

     //*. *,  !<!<a@   	 

 "&r*//EE=DJ"))%*E*EuMDJ	
w%"))%*E*EuMDJDJ3tyy7LMNN I  		


s   F6 5A#G6
GGc                     [        [        R                  " U R                  5        Vs/ s H  oR                  PM     sn6 5      $ s  snf rG   )r  r  r  get_childrenr   )rJ   xs     r,   r   Case._from_objects  s:    OOt7H7H7JK7J!oo7JKL
 	
Ks   A)r  r(   r5   r  N)r   r   r   r   r   r   r   dp_clauseelementdp_clauseelement_tuplesr&  r  r  r   r  r^   r-   r,   r  r  
  sa    0 N 
#445	#;;<	#445mO^ 
 
r-   r  c                     [        XSS9$ )a>  Produce a :class:`.ColumnClause` object that has the
:paramref:`_expression.column.is_literal` flag set to True.

: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:`_expression.column`
stores a string name that
will be assumed to be part of a table and may be quoted as such,
: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.
  Quoting rules will not be applied. To specify a column-name expression
  which should be subject to quoting rules, use the :func:`column`
  function.

:param type\_: an optional :class:`~sqlalchemy.types.TypeEngine`
  object which will
  provide result-set translation and additional expression semantics for
  this column. If left as ``None`` the type will be :class:`.NullType`.

.. seealso::

    :func:`_expression.column`

    :func:`_expression.text`

    :ref:`sqlexpression_literal_column`

T)r"   
is_literal)r  )r1  r"   s     r,   literal_columnr    s    B d;;r-   c                   z    \ rS rSrSrSrS\R                  4S\R                  4/r	S r
\S 5       r\S 5       rS	rg
)r  i  a  Represent a ``CAST`` expression.

:class:`.Cast` is produced using the :func:`.cast` factory function,
as in::

    from sqlalchemy import cast, Numeric

    stmt = select(cast(product_table.c.unit_price, Numeric(10, 4)))

Details on :class:`.Cast` usage is at :func:`.cast`.

.. seealso::

    :ref:`tutorial_casts`

    :func:`.cast`

    :func:`.type_coerce` - an alternative to CAST that coerces the type
    on the Python side only, which is often sufficient to generate the
    correct SQL and data coercion.

r  r@   r(   c                     [         R                  " U5      U l        [        R                  " [
        R                  UU R                  U S9U l        [        U R                  5      U l	        g)a  Produce a ``CAST`` expression.

:func:`.cast` returns an instance of :class:`.Cast`.

E.g.::

    from sqlalchemy import cast, Numeric

    stmt = select(cast(product_table.c.unit_price, Numeric(10, 4)))

The above statement will produce SQL resembling::

    SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

The :func:`.cast` function performs two distinct functions when
used.  The first is that it renders the ``CAST`` expression within
the resulting SQL string.  The second is that it associates the given
type (e.g. :class:`.TypeEngine` class or instance) with the column
expression on the Python side, which means the expression will take
on the expression operator behavior associated with that type,
as well as the bound-value handling and result-row-handling behavior
of the type.

.. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
   to the expression such that it takes effect on the bound-value,
   e.g. the Python-to-database direction, in addition to the
   result handling, e.g. database-to-Python, direction.

An alternative to :func:`.cast` is the :func:`.type_coerce` function.
This function performs the second task of associating an expression
with a specific type, but does not render the ``CAST`` expression
in SQL.

: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.

:param type\_: A :class:`.TypeEngine` class or instance indicating
 the type to which the ``CAST`` should apply.

.. seealso::

    :ref:`tutorial_casts`

    :func:`.type_coerce` - an alternative to CAST that coerces the type
    on the Python side only, which is often sufficient to generate the
    correct SQL and data coercion.


r"   r  N)
r	   to_instancer(   r   r#   r   r$   r@   r(  r)  rJ   r)   r"   s      r,   r  Cast.__init__  sQ    h ((/	&&''))"&	
 %TYY/r-   c                 .    U R                   R                  $ rG   r@   r   rj   s    r,   r   Cast._from_objectsN      {{(((r-   c                     U R                   $ rG   r?   rj   s    r,   r  Cast.wrapped_column_expressionR      {{r-   )r@   r(   r)  N)r   r   r   r   r   r   r   r	  r"  r&  r  r  r   r  r  r^   r-   r,   r  r    sd    . N 
$556	"**+
;0z ) )  r-   r  c                       \ rS rSrSrSrS\R                  4S\R                  4/r	S r
\S 5       r\R                  S 5       r\S	 5       rSS jrSrg
)
TypeCoerceiW  a  Represent a Python-side type-coercion wrapper.

: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
   a persistent :class:`.TypeCoerce` wrapper object rather than
   translating the given object in place.

.. seealso::

    :func:`_expression.type_coerce`

    :func:`.cast`

type_coercer@   r(   c                     [         R                  " U5      U l        [        R                  " [
        R                  UU R                  U S9U l        g)a=
  Associate a SQL expression with a particular type, without rendering
``CAST``.

E.g.::

    from sqlalchemy import type_coerce

    stmt = select(type_coerce(log_table.date_string, StringDateTime()))

The above construct will produce a :class:`.TypeCoerce` object, which
does not modify the rendering in any way on the SQL side, with the
possible exception of a generated label if used in a columns clause
context::

    SELECT date_string AS date_string FROM log

When result rows are fetched, the ``StringDateTime`` type processor
will be applied to result rows on behalf of the ``date_string`` column.

.. note:: the :func:`.type_coerce` construct does not render any
   SQL syntax of its own, including that it does not imply
   parenthesization.   Please use :meth:`.TypeCoerce.self_group`
   if explicit parenthesization is required.

In order to provide a named label for the expression, use
:meth:`_expression.ColumnElement.label`::

    stmt = select(
        type_coerce(log_table.date_string, StringDateTime()).label('date')
    )


A type that features bound-value handling will also have that behavior
take effect when literal values or :func:`.bindparam` constructs are
passed to :func:`.type_coerce` as targets.
For example, if a type implements the
:meth:`.TypeEngine.bind_expression`
method or :meth:`.TypeEngine.bind_processor` method or equivalent,
these functions will take effect at statement compilation/execution
time when a literal value is passed, as in::

    # bound-value handling of MyStringType will be applied to the
    # literal value "some string"
    stmt = select(type_coerce("some string", MyStringType))

When using :func:`.type_coerce` with composed expressions, note that
**parenthesis are not applied**.   If :func:`.type_coerce` is being
used in an operator context where the parenthesis normally present from
CAST are necessary, use the :meth:`.TypeCoerce.self_group` method::

    >>> some_integer = column("someint", Integer)
    >>> some_string = column("somestr", String)
    >>> expr = type_coerce(some_integer + 5, String) + some_string
    >>> print(expr)
    someint + :someint_1 || somestr
    >>> expr = type_coerce(some_integer + 5, String).self_group() + some_string
    >>> print(expr)
    (someint + :someint_1) || somestr

: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.

:param type\_: A :class:`.TypeEngine` class or instance indicating
 the type to which the expression is coerced.

.. seealso::

    :ref:`tutorial_casts`

    :func:`.cast`

r  N)r	   r  r(   r   r#   r   r$   r@   r  s      r,   r  TypeCoerce.__init__p  s?    V ((/	&&''))"&	
r-   c                 .    U R                   R                  $ rG   r  rj   s    r,   r   TypeCoerce._from_objects  r  r-   c                     [        U R                  [        5      (       a-  U R                  R                  5       nU R                  Ul        U$ U R                  $ rG   )r  r@   r:   r   r(   )rJ   bps     r,   typed_expressionTypeCoerce.typed_expression  s?    dkk=11##%BiiBGI;;r-   c                     U R                   $ rG   r?   rj   s    r,   r  $TypeCoerce.wrapped_column_expression  r  r-   Nc                 ~    U R                   R                  US9nX R                   La  [        X R                  5      $ U $ r  )r@   r   r  r(   )rJ   r   groupeds      r,   r   TypeCoerce.self_group  s7    ++(((9++%gyy11Kr-   )r@   r(   rG   )r   r   r   r   r   r   r   r	  r"  r&  r  r  r   r   r  r$  r  r   r  r^   r-   r,   r  r  W  s    " #N 
$556	"**+
Q
f ) ) ## $  r-   r  c                   j    \ rS rSrSrSrS\R                  4S\R                  4/r	S r
\S 5       rSrg	)
Extracti  z=Represent a SQL EXTRACT clause, ``extract(field FROM expr)``.extractr+   fieldc                     [         R                  U l        Xl        [        R
                  " [        R                  U5      U l        g)a  Return a :class:`.Extract` construct.

This is typically available as :func:`.extract`
as well as ``func.extract`` from the
:data:`.func` namespace.

:param field: The field to extract.

:param expr: A column or Python scalar expression serving as the
  right side of the ``EXTRACT`` expression.

E.g.::

    from sqlalchemy import extract
    from sqlalchemy import table, column

    logged_table = table("user",
            column("id"),
            column("date_created"),
    )

    stmt = select(logged_table.c.id).where(
        extract("YEAR", logged_table.c.date_created) == 2021
    )

In the above example, the statement is used to select ids from the
database where the ``YEAR`` component matches a specific value.

Similarly, one can also select an extracted component::

    stmt = select(
        extract("YEAR", logged_table.c.date_created)
    ).where(logged_table.c.id == 1)

The implementation of ``EXTRACT`` may vary across database backends.
Users are reminded to consult their database documentation.
N)	r	   INTEGERTYPEr(   r.  r   r#   r   r$   r+   )rJ   r.  r+   r   s       r,   r  Extract.__init__  s1    L ((	
$$U%@%@$G	r-   c                 .    U R                   R                  $ rG   )r+   r   rj   s    r,   r   Extract._from_objects  s    yy&&&r-   )r+   r.  r(   N)r   r   r   r   r   r   r   r	  rd  r&  r  r  r   r  r^   r-   r,   r,  r,    sM    GN 
"334	#--.
(HT ' 'r-   r,  c                   P    \ rS rSrSrSrS\R                  4/rS r	\
S 5       rSrg)	_label_referencei  a  Wrap a column expression as it appears in a 'reference' context.

This expression is any that includes an _order_by_label_element,
which is a Label, or a DESC / ASC construct wrapping a Label.

The production of _label_reference() should occur when an expression
is added to this context; this includes the ORDER BY or GROUP BY of a
SELECT statement, as well as a few other places, such as the ORDER BY
within an OVER clause.

label_referenceelementc                     Xl         g rG   r7  rJ   r7  s     r,   r  _label_reference.__init__&      r-   c                     g)Nr^   r^   rj   s    r,   r   _label_reference._from_objects)  s    r-   r9  N)r   r   r   r   r   r   r   r	  r&  r  r  r   r  r^   r-   r,   r5  r5    s<    
 'N%'8'I'IJK  r-   r5  c                   `    \ rS rSrSrS\R                  4/rS r\	R                  S 5       rSrg)_textual_label_referencei.  textual_label_referencer7  c                     Xl         g rG   r9  r:  s     r,   r  !_textual_label_reference.__init__3  r<  r-   c                 @    [         R                  U R                  5      $ rG   )r.  rI  r7  rj   s    r,   _text_clause%_textual_label_reference._text_clause6  s    &&t||44r-   r9  N)r   r   r   r   r   r   rd  r&  r  r   r  rE  r  r^   r-   r,   r@  r@  .  s;    .N%'8'B'BCD 
5 5r-   r@  c                       \ rS rSrSrSrS\R                  4S\R                  4S\R                  4/r	    SS jr
\S	 5       r\S
 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rS rSS jrSrg)r   i;  a  Define a 'unary' expression.

A unary expression has a single column expression
and an operator.  The operator can be placed on the left
(where it is called the 'operator') or right (where it is called the
'modifier') of the column expression.

:class:`.UnaryExpression` is the basis for several unary operators
including those used by :func:`.desc`, :func:`.asc`, :func:`.distinct`,
:func:`.nulls_first` and :func:`.nulls_last`.

unaryr7  r   modifierNc                     X l         X0l        UR                  U l        UR                  U R                   =(       d    U R                  S9U l        [
        R                  " U5      U l        XPl        g r  )	r   rI  rI   r   r7  r	   r  r(   wraps_column_expression)rJ   r7  r   rI  r"   rK  s         r,   r  UnaryExpression.__init__Q  s]     !  ' 8 8))MM2T]] * 
 ((/	'>$r-   c                 z    [        [        R                  " [        R                  U5      [
        R                  SS9$ )ab  Produce the ``NULLS FIRST`` modifier for an ``ORDER BY`` expression.

:func:`.nulls_first` is intended to modify the expression produced
by :func:`.asc` or :func:`.desc`, and indicates how NULL values
should be handled when they are encountered during ordering::


    from sqlalchemy import desc, nulls_first

    stmt = select(users_table).order_by(
        nulls_first(desc(users_table.c.name)))

The SQL expression from the above would resemble::

    SELECT id, name FROM user ORDER BY name DESC NULLS FIRST

Like :func:`.asc` and :func:`.desc`, :func:`.nulls_first` is typically
invoked from the column expression itself using
:meth:`_expression.ColumnElement.nulls_first`,
rather than as its standalone
function version, as in::

    stmt = select(users_table).order_by(
        users_table.c.name.desc().nulls_first())

.. versionchanged:: 1.4 :func:`.nulls_first` is renamed from
    :func:`.nullsfirst` in previous releases.
    The previous name remains available for backwards compatibility.

.. seealso::

    :func:`.asc`

    :func:`.desc`

    :func:`.nulls_last`

    :meth:`_expression.Select.order_by`

FrI  rK  )r   r   r#   r   ByOfRoler   nulls_first_oprH  columns     r,   _create_nulls_first#UnaryExpression._create_nulls_firstb  s2    T U^^V4--$)
 	
r-   c                 z    [        [        R                  " [        R                  U5      [
        R                  SS9$ )aY  Produce the ``NULLS LAST`` modifier for an ``ORDER BY`` expression.

:func:`.nulls_last` is intended to modify the expression produced
by :func:`.asc` or :func:`.desc`, and indicates how NULL values
should be handled when they are encountered during ordering::


    from sqlalchemy import desc, nulls_last

    stmt = select(users_table).order_by(
        nulls_last(desc(users_table.c.name)))

The SQL expression from the above would resemble::

    SELECT id, name FROM user ORDER BY name DESC NULLS LAST

Like :func:`.asc` and :func:`.desc`, :func:`.nulls_last` is typically
invoked from the column expression itself using
:meth:`_expression.ColumnElement.nulls_last`,
rather than as its standalone
function version, as in::

    stmt = select(users_table).order_by(
        users_table.c.name.desc().nulls_last())

.. versionchanged:: 1.4 :func:`.nulls_last` is renamed from
    :func:`.nullslast` in previous releases.
    The previous name remains available for backwards compatibility.

.. seealso::

    :func:`.asc`

    :func:`.desc`

    :func:`.nulls_first`

    :meth:`_expression.Select.order_by`

FrN  )r   r   r#   r   rO  r   nulls_last_oprQ  s     r,   _create_nulls_last"UnaryExpression._create_nulls_last  s2    T U^^V4,,$)
 	
r-   c                 z    [        [        R                  " [        R                  U5      [
        R                  SS9$ )a  Produce a descending ``ORDER BY`` clause element.

e.g.::

    from sqlalchemy import desc

    stmt = select(users_table).order_by(desc(users_table.c.name))

will produce SQL as::

    SELECT id, name FROM user ORDER BY name DESC

The :func:`.desc` function is a standalone version of the
: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:`_expression.ColumnElement` (e.g.
 scalar SQL expression)
 with which to apply the :func:`.desc` operation.

.. seealso::

    :func:`.asc`

    :func:`.nulls_first`

    :func:`.nulls_last`

    :meth:`_expression.Select.order_by`

FrN  )r   r   r#   r   rO  r   desc_oprQ  s     r,   _create_descUnaryExpression._create_desc  s2    J U^^V4&&$)
 	
r-   c                 z    [        [        R                  " [        R                  U5      [
        R                  SS9$ )a  Produce an ascending ``ORDER BY`` clause element.

e.g.::

    from sqlalchemy import asc
    stmt = select(users_table).order_by(asc(users_table.c.name))

will produce SQL as::

    SELECT id, name FROM user ORDER BY name ASC

The :func:`.asc` function is a standalone version of the
: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:`_expression.ColumnElement` (e.g.
 scalar SQL expression)
 with which to apply the :func:`.asc` operation.

.. seealso::

    :func:`.desc`

    :func:`.nulls_first`

    :func:`.nulls_last`

    :meth:`_expression.Select.order_by`

FrN  )r   r   r#   r   rO  r   asc_oprQ  s     r,   _create_ascUnaryExpression._create_asc  s2    H U^^V4%%$)
 	
r-   c                     [         R                  " [        R                  U5      n[	        U[
        R                  UR                  SS9$ )a  Produce an column-expression-level unary ``DISTINCT`` clause.

This applies the ``DISTINCT`` keyword to an individual column
expression, and is typically contained within an aggregate function,
as in::

    from sqlalchemy import distinct, func
    stmt = select(func.count(distinct(users_table.c.name)))

The above would produce an expression resembling::

    SELECT COUNT(DISTINCT name) FROM user

The :func:`.distinct` function is also available as a column-level
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:`_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
information.

.. seealso::

    :meth:`_expression.ColumnElement.distinct`

    :meth:`_expression.Select.distinct`

    :data:`.func`

Fr   r"   rK  )r   r#   r   r$   r   r   distinct_opr(   rH  r+   s     r,   _create_distinct UnaryExpression._create_distinct  s@    J  ; ;TB**))$)	
 	
r-   c                     U R                   [        R                  [        R                  4;   a  U R                  R
                  $ g rG   )rI  r   rZ  r^  r7  r  rj   s    r,   r  'UnaryExpression._order_by_label_elementD  s2    ==Y..	0@0@AA<<777r-   c                 .    U R                   R                  $ rG   r7  r   rj   s    r,   r   UnaryExpression._from_objectsK      ||)))r-   c                 (   U R                   R                  [        R                  R                  L aM  [	        U R                  [        R                  S9[        R                  [        R                  U R                  S9$ [        R                  U 5      $ )Nr   rb  )r(   r,  r	   r-  r   r   r   r>   rK  rC   r   rj   s    r,   r   UnaryExpression._negateO  sk    99##x';';'J'JJ"	6"**(,(D(D	  !((..r-   c                     U R                   (       a1  [        R                  " U R                   U5      (       a  [        U 5      $ U $ rG   )r   r   r  r3  r   s     r,   r   UnaryExpression.self_groupZ  s.    ==Y33DMM7KKD>!Kr-   )rI   r7  rI  r   r(   rK  )NNNFrG   )r   r   r   r   r   r   r   r	  r  r&  r  rj  rS  rW  r[  r_  re  r  r  r   r   r   r  r^   r-   r,   r   r   ;  s     N 
%667	&223	&223  %?" -
 -
^ -
 -
^ (
 (
T '
 '
R *
 *
X   * *	/r-   r   c                   H    \ rS rSrSrSr\S 5       r\S 5       rS r	S r
Srg	)
CollectionAggregateia  zForms the basis for right-hand collection operator modifiers
ANY and ALL.

The ANY and ALL keywords are available in different ways on different
backends.  On PostgreSQL, they only work for an ARRAY type.  On
MySQL, they only work for subqueries.

Tc                     [         R                  " [        R                  U5      nUR	                  5       n[        U[        R                  [        R                  SS9$ )a  Produce an ANY expression.

For dialects such as that of PostgreSQL, this operator applies
to usage of the :class:`_types.ARRAY` datatype, for that of
MySQL, it may apply to a subquery.  e.g.::

    # renders on PostgreSQL:
    # '5 = ANY (somearray)'
    expr = 5 == any_(mytable.c.somearray)

    # renders on MySQL:
    # '5 = ANY (SELECT value FROM table)'
    expr = 5 == any_(select(table.c.value))

Comparison to NULL may work using ``None`` or :func:`_sql.null`::

    None == any_(mytable.c.somearray)

The any_() / all_() operators also feature a special "operand flipping"
behavior such that if any_() / all_() are used on the left side of a
comparison using a standalone operator such as ``==``, ``!=``, etc.
(not including operator methods such as
:meth:`_sql.ColumnOperators.is_`) the rendered expression is flipped::

    # would render '5 = ANY (column)`
    any_(mytable.c.column) == 5

Or with ``None``, which note will not perform
the usual step of rendering "IS" as is normally the case for NULL::

    # would render 'NULL = ANY(somearray)'
    any_(mytable.c.somearray) == None

.. versionchanged:: 1.4.26  repaired the use of any_() / all_()
   comparing to NULL on the right side to be flipped to the left.

The column-level :meth:`_sql.ColumnElement.any_` method (not to be
confused with :class:`_types.ARRAY` level
:meth:`_types.ARRAY.Comparator.any`) is shorthand for
``any_(col)``::

    5 = mytable.c.somearray.any_()

.. seealso::

    :meth:`_sql.ColumnOperators.any_`

    :func:`_expression.all_`

Frb  )
r   r#   r   r$   r   rr  r   r1  r	   r;  rd  s     r,   _create_anyCollectionAggregate._create_anym  sN    j  ; ;TB "%%##$)	
 	
r-   c                     [         R                  " [        R                  U5      nUR	                  5       n[        U[        R                  [        R                  SS9$ )a  Produce an ALL expression.

For dialects such as that of PostgreSQL, this operator applies
to usage of the :class:`_types.ARRAY` datatype, for that of
MySQL, it may apply to a subquery.  e.g.::

    # renders on PostgreSQL:
    # '5 = ALL (somearray)'
    expr = 5 == all_(mytable.c.somearray)

    # renders on MySQL:
    # '5 = ALL (SELECT value FROM table)'
    expr = 5 == all_(select(table.c.value))

Comparison to NULL may work using ``None``::

    None == all_(mytable.c.somearray)

The any_() / all_() operators also feature a special "operand flipping"
behavior such that if any_() / all_() are used on the left side of a
comparison using a standalone operator such as ``==``, ``!=``, etc.
(not including operator methods such as
:meth:`_sql.ColumnOperators.is_`) the rendered expression is flipped::

    # would render '5 = ALL (column)`
    all_(mytable.c.column) == 5

Or with ``None``, which note will not perform
the usual step of rendering "IS" as is normally the case for NULL::

    # would render 'NULL = ALL(somearray)'
    all_(mytable.c.somearray) == None

.. versionchanged:: 1.4.26  repaired the use of any_() / all_()
   comparing to NULL on the right side to be flipped to the left.

The column-level :meth:`_sql.ColumnElement.all_` method (not to be
confused with :class:`_types.ARRAY` level
:meth:`_types.ARRAY.Comparator.all`) is shorthand for
``all_(col)``::

    5 == mytable.c.somearray.all_()

.. seealso::

    :meth:`_sql.ColumnOperators.all_`

    :func:`_expression.any_`

Frb  )
r   r#   r   r$   r   rr  r   r2  r	   r;  rd  s     r,   _create_allCollectionAggregate._create_all  sN    h  ; ;TB "%%##$)	
 	
r-   c                     [         R                  " U5      (       d  [        R                  " S5      eS=US'   US'   U R                  R
                  " [         R                  " U5      /UQ70 UD6$ )N2Only comparison operators may be used with ANY/ALLTreverse_any_all_expr)r   is_comparisonr   r   rD  rR  mirrorrP  s       r,   rR  CollectionAggregate.operate  si    &&r**##D  7;:yF?3&&y'7'7';NeNvNNr-   c                 h    [         R                  " U5      (       a   e[        R                  " S5      e)Nrz  )r   r}  r   r   rP  s       r,   rU  #CollectionAggregate.reverse_operate  s/    **2....@
 	
r-   r^   N)r   r   r   r   r   r  rj  rt  rw  rR  rU  r  r^   r-   r,   rr  rr  a  sA     M<
 <
| :
 :
~O
r-   rr  c                   >    \ rS rSrSrS r\S 5       rS	S jrS r	Sr
g)
r.  i  Tc                     Xl         [        R                  U l        X l        X0l        S U l        SU l        UR                  U l        g r  )	r7  r	   r-  r(   r   negaterI  rK  r  )rJ   r7  r   r  s       r,   r  AsBoolean.__init__  s;    ((	 '+$&-&D&D#r-   c                     U R                   $ rG   r9  rj   s    r,   r  #AsBoolean.wrapped_column_expression  s    ||r-   Nc                     U $ rG   r^   r   s     r,   r   AsBoolean.self_group      r-   c                     [        U R                  [        [        45      (       a  U R                  R	                  5       $ [        U R                  U R                  U R                  5      $ rG   )r  r7  r~  rv  r   r.  r  r   rj   s    r,   r   AsBoolean._negate  sE    dllUFO44<<''))T\\4;;FFr-   )r  r7  rI  r  r   r(   rK  rG   )r   r   r   r   r  r  r  r  r   r   r  r^   r-   r,   r.  r.    s,    ME  Gr-   r.  c                     ^  \ rS rSrSrSrS\R                  4S\R                  4S\R                  4S\R                  4S\R                  4S	\R                  4/rS\R                  4S\R                  4S\R                  4S\R                  4S	\R                  4/rS
r  SS jrS r\r\S 5       r\S 5       rSS jrU 4S jrSrU =r$ )r%   i  a  Represent an expression that is ``LEFT <operator> RIGHT``.

A :class:`.BinaryExpression` is generated automatically
whenever two column expressions are used in a Python binary expression::

    >>> from sqlalchemy.sql import column
    >>> column('a') + column('b')
    <sqlalchemy.sql.expression.BinaryExpression object at 0x101029dd0>
    >>> print(column('a') + column('b'))
    a + b

binaryleftrightr   r  	modifiersr(   Tc                    [        U[        R                  5      (       a  [        R                  " U5      nUR                  5       UR                  5       4U l        UR                  =(       d    UR                  U l        UR                  US9U l	        UR                  US9U l
        X0l        [        R                  " U5      U l        XPl        [        R                   " U5      U l        Uc  0 U l        g X`l        g r  )r  r   string_typesr   	custom_op__hash___origrI   r   r  r  r   r	   r  r(   r  r  r  r  )rJ   r  r  r   r"   r  r  s          r,   r  BinaryExpression.__init__E  s    
 h 1 122 **84Hmmou~~'78
 $ 5 5 O9O9OOOHO5	%%h%7
 ((/	&/&:&:8&D#DN&Nr-   c                     U R                   [         R                  [         R                  4;   a  U R                   " U R                  6 $ [	        S5      er   )r   eqner  r   rj   s    r,   r   BinaryExpression.__bool__Z  s:    ==X[[(++66==$**--IJJr-   c                 B    [         R                  " U R                  5      $ rG   )r   r}  r   rj   s    r,   r}  BinaryExpression.is_comparisonb  s    &&t}}55r-   c                 \    U R                   R                  U R                  R                  -   $ rG   )r  r   r  rj   s    r,   r   BinaryExpression._from_objectsf  s!    yy&&)A)AAAr-   c                 h    [         R                  " U R                  U5      (       a  [        U 5      $ U $ rG   )r   r  r   r3  r   s     r,   r   BinaryExpression.self_groupj  s(    !!$--99D>!Kr-   c           	        > U R                   bn  [        U R                  U R                  R	                  U R                   U R
                  5      U R                   U R
                  U R                  U R                  S9$ [        [        U ]'  5       $ )N)r  r"   r  )
r  r%   r  r  ra   r   r(   r  r6  r   r7  s    r,   r   BinaryExpression._negateq  sl    ;;"#		

,,T[[$--H}}ii..  )48::r-   )	r  r  rI   r  r  r  r   r  r(   )NNNrG   )r   r   r   r   r   r   r   r	  r  r#  r"  r&  r  r  r  r   r  r  r}  r   r   r   r  r  ri   s   @r,   r%   r%     s+    N 
"334	#445	&223	$001	'556%%	

 
"334	#445	&223	'556 %%	
 " IM'*K K6 6 B B; ;r-   r%   c                       \ rS rSrSrSrS\R                  4S\R                  4S\R                  4/rSS jr	SS	 jr
S
rg)Slicei  zRepresent SQL for a Python array-slice object.

This is not a specific SQL construct at this level, but
may be interpreted by specific dialects, e.g. PostgreSQL.

slicestartstopstepNc                 ~   [         R                  " [        R                  UU[        R
                  S9U l        [         R                  " [        R                  UU[        R
                  S9U l        [         R                  " [        R                  UU[        R
                  S9U l        [        R                  U l
        g )N)r$  r"   )r   r#   r   r$   r	   r0  r  r  r  r;  r(   )rJ   r  r  r  _names        r,   r  Slice.__init__  s    %%''&&	

 $$''&&	
	 $$''&&	
	 %%	r-   c                 0    U[         R                  L d   eU $ rG   )r   getitemr   s     r,   r   Slice.self_group  s    (*****r-   )r  r  r  r(   rG   )r   r   r   r   r   r   r   r	  r&  r  r   r  r^   r-   r,   r  r    sO     N 
#445	"334	"334&*r-   r  c                       \ rS rSrSrSrSrg)IndexExpressioni  zFRepresent the class of expressions that are like an "index"
operation.Tr^   N)r   r   r   r   r   r  r  r^   r-   r,   r  r    s     Mr-   r  c                   ,    \ rS rSrSrSrSS jrS rSrg)	GroupedElementi  z&Represent any parenthesized expressiongroupingNc                     U $ rG   r^   r   s     r,   r   GroupedElement.self_group  r  r-   c                 6    U R                   R                  5       $ rG   )r7  r   rj   s    r,   r   GroupedElement._ungroup  s    ||$$&&r-   r^   rG   )	r   r   r   r   r   r   r   r   r  r^   r-   r,   r  r    s    0N'r-   r  c                       \ rS rSrSrS\R                  4S\R                  4/rS\R                  4/r	S r
S r\R                  S 5       r\S 5       r\S	 5       r\S
 5       rS rS rS rSrg)r3  i  z/Represent a grouping within a column expressionr7  r(   c                 P    Xl         [        US[        R                  5      U l        g Nr(   )r7  r%  r	   r;  r(   r:  s     r,   r  Grouping.__init__  s    GVX->->?	r-   c                 V    U R                  U R                  R                  U5      5      $ rG   )rP   r7  rf   re   s     r,   rf   "Grouping._with_binary_element_type  s     ~~dllDDUKLLr-   c                 .    U R                   R                  $ rG   r7  r  rj   s    r,   r  Grouping._is_implicitly_boolean      ||222r-   c                 V    [        U R                  SS 5      =(       d    U R                  $ r  )r%  r7  r  rj   s    r,   r   Grouping._tq_label  s$     DLL+t4M8M8M	
r-   c                 ^    [        U R                  [        5      (       a  U R                  /$ / $ rG   )r  r7  r  rj   s    r,   rg  Grouping._proxies  s$    dllM22LL>!Ir-   c                 .    U R                   R                  $ rG   rj  rj   s    r,   r   Grouping._from_objects  rl  r-   c                 .    [        U R                  U5      $ rG   )r%  r7  )rJ   attrs     r,   rL  Grouping.__getattr__  s    t||T**r-   c                 4    U R                   U R                  S.$ )Nr7  r(   r  rj   s    r,   r|   Grouping.__getstate__  s    <<;;r-   c                 ,    US   U l         US   U l        g )Nr7  r(   r  rG  s     r,   rI  Grouping.__setstate__  s    Y'&M	r-   r  N)r   r   r   r   r   r   r	  r"  r&  r  r  rf   r   r  r  r  r   rg  r   rL  r|   rI  r  r^   r-   r,   r3  r3    s    9 
%667	"**+ 
%667@M 
3 3 
 

   * *+<"r-   r3  RANGE_UNBOUNDEDRANGE_CURRENTc                       \ rS rSrSrSrS\R                  4S\R                  4S\R                  4S\R                  4S\R                  4/r	S	r
S	rS	r  SS
 jrS rS r\R"                  S 5       r\S 5       rSrg	)Overi  zRepresent an OVER clause.

This is a special operator against a so-called
"window" function, as well as any aggregate function,
which produces results relative to the result set
itself.  Most modern SQL backends now support window functions.

overr7  order_bypartition_byrange_rowsNc                    Xl         Ub2  [        [        R                  " U5      S[        R
                  06U l        Ub2  [        [        R                  " U5      S[        R
                  06U l        U(       a;  U R                  U5      U l	        U(       a  [        R                  " S5      eSU l        gU(       a  U R                  U5      U l        SU l	        gS=U l        U l	        g)a 
  Produce an :class:`.Over` object against a function.

Used against aggregate or so-called "window" functions,
for database backends that support window functions.

:func:`_expression.over` is usually called using
the :meth:`.FunctionElement.over` method, e.g.::

    func.row_number().over(order_by=mytable.c.some_column)

Would produce::

    ROW_NUMBER() OVER(ORDER BY some_column)

Ranges are also possible using the :paramref:`.expression.over.range_`
and :paramref:`.expression.over.rows` parameters.  These
mutually-exclusive parameters each accept a 2-tuple, which contains
a combination of integers and None::

    func.row_number().over(
        order_by=my_table.c.some_column, range_=(None, 0))

The above would produce::

    ROW_NUMBER() OVER(ORDER BY some_column
    RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)

A value of ``None`` indicates "unbounded", a
value of zero indicates "current row", and negative / positive
integers indicate "preceding" and "following":

* RANGE BETWEEN 5 PRECEDING AND 10 FOLLOWING::

    func.row_number().over(order_by='x', range_=(-5, 10))

* ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW::

    func.row_number().over(order_by='x', rows=(None, 0))

* RANGE BETWEEN 2 PRECEDING AND UNBOUNDED FOLLOWING::

    func.row_number().over(order_by='x', range_=(-2, None))

* RANGE BETWEEN 1 FOLLOWING AND 3 FOLLOWING::

    func.row_number().over(order_by='x', range_=(1, 3))

.. versionadded:: 1.1 support for RANGE / ROWS within a window


:param element: a :class:`.FunctionElement`, :class:`.WithinGroup`,
 or other compatible construct.
:param partition_by: a column element or string, or a list
 of such, that will be used as the PARTITION BY clause
 of the OVER construct.
:param order_by: a column element or string, or a list
 of such, that will be used as the ORDER BY clause
 of the OVER construct.
:param range\_: optional range clause for the window.  This is a
 tuple value which can contain integer values or ``None``,
 and will render a RANGE BETWEEN PRECEDING / FOLLOWING clause.

 .. versionadded:: 1.1

:param rows: optional rows clause for the window.  This is a tuple
 value which can contain integer values or None, and will render
 a ROWS BETWEEN PRECEDING / FOLLOWING clause.

 .. versionadded:: 1.1

This function is also available from the :data:`~.expression.func`
construct itself via the :meth:`.FunctionElement.over` method.

.. seealso::

    :ref:`tutorial_window_functions` - in the :ref:`unified_tutorial`

    :data:`.expression.func`

    :func:`_expression.within_group`

Nr  z*'range_' and 'rows' are mutually exclusive)r7  r  r   to_listr   rO  r  r  _interpret_ranger  r   r   r  )rJ   r7  r  r  r  r  s         r,   r  Over.__init__  s    j &h'?D~~DM # *l+!&+nn!D
 //7DK''@  !	--d3DIDK&**DIr-   c                     U R                   U R                  U R                  U R                  U R                  U R
                  44$ rG   )rP   r7  r  r  r  r  rj   s    r,   
__reduce__Over.__reduce__|  s=    ~~LLMMKKII 
 
 	
r-   c                 *   [        U[        5      (       a  [        U5      S:w  a  [        R                  " S5      eUS   c  [
        nO [        US   5      nUS:X  a  [        nUS   c
  [
        nWU4$  [        US   5      nUS:X  a  [        nWU4$ ! [         a3  n[        R                  " [        R                  " S5      US9   S nANgS nAff = f! [         a6  n[        R                  " [        R                  " S5      US9   S nAWW4$ S nAff = f)Nr   z2-tuple expected for range/rowsr   z(Integer or None expected for range valuer?  r   )r  r   r   r   r   r  intr  
ValueErrorr   rB  )rJ   r  lowerrC  uppers        r,   r  Over._interpret_range  s   &%((CK1,<##$EFF!9#E*F1I A:)E!9#E e|*F1I A:)Ee|7  %%B %(	   %%B %(	 e|s0   	B 4C 
C)C

C
D)DDc                 .    U R                   R                  $ rG   r  rj   s    r,   r(   	Over.type  s    ||   r-   c                     [        [        R                  " U R                  U R                  U R
                  4 Vs/ s H  nUc  M  UR                  PM     sn6 5      $ s  snf rG   )r  r  r  r7  r  r  r   r  s     r,   r   Over._from_objects  s[    OO #llD,=,=t}}MM $AOOM
 	
s   AA)r7  r  r  r  r  NNNN)r   r   r   r   r   r   r   r	  r$  r&  r  r  r7  r  r  r  r   r  r(   r  r   r  r^   r-   r,   r  r    s     N 
%667	&778	*;;<	$112	"//0 HLG LPl+\
$L 
! ! 	
 	
r-   r  c                       \ rS rSrSrSrS\R                  4S\R                  4/rSr	S r
S rSS	 jr\R                  S
 5       r\S 5       rSrg)WithinGroupi  a  Represent a WITHIN GROUP (ORDER BY) clause.

This is a special operator against so-called
"ordered set aggregate" and "hypothetical
set aggregate" functions, including ``percentile_cont()``,
``rank()``, ``dense_rank()``, etc.

It's supported only by certain database backends, such as PostgreSQL,
Oracle and MS SQL Server.

The :class:`.WithinGroup` construct extracts its type from the
method :meth:`.FunctionElement.within_group_type`.  If this returns
``None``, the function's ``.type`` is used.

withingroupr7  r  Nc                 |    Xl         Ub3  [        [        R                  " U5      S[        R
                  06U l        gg)a=  Produce a :class:`.WithinGroup` object against a function.

Used against so-called "ordered set aggregate" and "hypothetical
set aggregate" functions, including :class:`.percentile_cont`,
:class:`.rank`, :class:`.dense_rank`, etc.

:func:`_expression.within_group` is usually called using
the :meth:`.FunctionElement.within_group` method, e.g.::

    from sqlalchemy import within_group
    stmt = select(
        department.c.id,
        func.percentile_cont(0.5).within_group(
            department.c.salary.desc()
        )
    )

The above statement would produce SQL similar to
``SELECT department.id, percentile_cont(0.5)
WITHIN GROUP (ORDER BY department.salary DESC)``.

:param element: a :class:`.FunctionElement` construct, typically
 generated by :data:`~.expression.func`.
:param \*order_by: one or more column elements that will be used
 as the ORDER BY clause of the WITHIN GROUP construct.

.. versionadded:: 1.1

.. seealso::

    :ref:`tutorial_functions_within_group` - in the
    :ref:`unified_tutorial`

    :data:`.expression.func`

    :func:`_expression.over`

Nr  )r7  r  r   r  r   rO  r  )rJ   r7  r  s      r,   r  WithinGroup.__init__  s9    N &h'?D~~DM  r-   c                 `    U R                   U R                  4[        U R                  5      -   4$ rG   )rP   r7  r   r  rj   s    r,   r  WithinGroup.__reduce__  s%    ~~t}}1EEEEr-   c                     [        U UUUUS9$ )zProduce an OVER clause against this :class:`.WithinGroup`
construct.

This function has the same signature as that of
:meth:`.FunctionElement.over`.

r  r  r  r  r  rJ   r  r  r  r  s        r,   r  WithinGroup.over  s      %
 	
r-   c                 n    U R                   R                  U 5      nUb  U$ U R                   R                  $ rG   )r7  within_group_typer(   )rJ   wgts     r,   r(   WithinGroup.type  s0    ll,,T2?J<<$$$r-   c                     [        [        R                  " U R                  U R                  4 Vs/ s H  nUc  M  UR
                  PM     sn6 5      $ s  snf rG   )r  r  r  r7  r  r   r  s     r,   r   WithinGroup._from_objects  sS    OO #llDMM:: $AOO:
 	

   AA)r7  r  r  )r   r   r   r   r   r   r   r	  r&  r  r  r  r  r   r  r(   r  r   r  r^   r-   r,   r  r    s|      #N 
%667	&778
 H+ZF
  
% % 	
 	
r-   r  c                       \ rS rSrSrSrS\R                  4S\R                  4/rSr	S r
S rSS	 jrSS
 jr\R                  S 5       r\S 5       rSrg)FunctionFilteri+  a  Represent a function FILTER clause.

This is a special operator against aggregate and window functions,
which controls which rows are passed to it.
It's supported only by certain database backends.

Invocation of :class:`.FunctionFilter` is via
:meth:`.FunctionElement.filter`::

    func.count(1).filter(True)

.. versionadded:: 1.0.0

.. seealso::

    :meth:`.FunctionElement.filter`


funcfilterfunc	criterionNc                 .    Xl         U R                  " U6   g)av  Produce a :class:`.FunctionFilter` object against a function.

Used against aggregate and window functions,
for database backends that support the "FILTER" clause.

E.g.::

    from sqlalchemy import funcfilter
    funcfilter(func.count(1), MyClass.name == 'some name')

Would produce "COUNT(1) FILTER (WHERE myclass.name = 'some name')".

This function is also available from the :data:`~.expression.func`
construct itself via the :meth:`.FunctionElement.filter` method.

.. versionadded:: 1.0.0

.. seealso::

    :ref:`tutorial_functions_within_group` - in the
    :ref:`unified_tutorial`

    :meth:`.FunctionElement.filter`

N)r  filter)rJ   r  r  s      r,   r  FunctionFilter.__init__H  s    4 	Yr-   c                     [        U5       HQ  n[        R                  " [        R                  U5      nU R
                  b  U R
                  U-  U l        MK  Xl        MS     U $ )zProduce an additional FILTER against the function.

This method adds additional criteria to the initial criteria
set up by :meth:`.FunctionElement.filter`.

Multiple criteria are joined together at SQL render time
via ``AND``.


)r  r   r#   r   r  r  )rJ   r  s     r,   r  FunctionFilter.filtere  sP     iI!(()>)>	JI~~)!%)!;!* ) r-   c                     [        U UUUUS9$ )a  Produce an OVER clause against this filtered function.

Used against aggregate or so-called "window" functions,
for database backends that support window functions.

The expression::

    func.rank().filter(MyClass.y > 5).over(order_by='x')

is shorthand for::

    from sqlalchemy import over, funcfilter
    over(funcfilter(func.rank(), MyClass.y > 5), order_by='x')

See :func:`_expression.over` for a full description.

r  r  r  s        r,   r  FunctionFilter.over{  s     $ %
 	
r-   c                 p    [         R                  " [         R                  U5      (       a  [        U 5      $ U $ rG   )r   r  	filter_opr3  r   s     r,   r   FunctionFilter.self_group  s*    !!)"5"5w??D>!Kr-   c                 .    U R                   R                  $ rG   )r  r(   rj   s    r,   r(   FunctionFilter.type  s    yy~~r-   c                     [        [        R                  " U R                  U R                  4 Vs/ s H  nUc  M  UR
                  PM     sn6 5      $ s  snf rG   )r  r  r  r  r  r   r  s     r,   r   FunctionFilter._from_objects  sS    OO #ii88 $AOO8
 	
r  )r  r  r  rG   )r   r   r   r   r   r   r   r	  r&  r  r  r  r  r   r   r  r(   r  r   r  r^   r-   r,   r   r   +  s    & "N 
"334	'889
 I :,
4 
  	
 	
r-   r   c                      \ rS rSrSrSrS\R                  4S\R                  4S\R                  4/r
S\R                  4S\R                  4/rSS jrS	 r\R                  S
 5       r\R$                  S 5       r\S 5       r\R                  S 5       r\R$                  S 5       rSS jrS rS r\S 5       r\S 5       r\S4S jr\S 5       rSS jr Sr!g)r  i  zRepresents a column label (AS).

Represent a label, as typically applied to any column-level
element using the ``AS`` sql keyword.

r  r$  _type_elementNc                    Un[         R                  " [        R                  UU S9n[	        U[
        5      (       a#  UR                  n[	        U[
        5      (       a  M#  U(       a  Xl        OU[        R                  [        U 5      [        USS5      5      U l        [	        U[
        5      (       a  UR                  U l        U R                  =U l        =U l        U l        X l        X0l        U/U l        g)a  Return a :class:`Label` object for the
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:`_expression.ColumnElement.label` method on
:class:`_expression.ColumnElement`.

:param name: label name

:param obj: a :class:`_expression.ColumnElement`.

r  r$  r  N)r   r#   r   r$   r  r  r7  r$  r  r  r   r%  r!  _resolve_labelr;   r   r  r  r  rg  )rJ   r$  r7  r"   orig_elements        r,   r  Label.__init__  s    " ""''"&

 %(( ooG %((
 I(774''66:DI ,.. '3&9&9#9=BB4>D$6
 	r-   c                 `    U R                   U R                  U R                  U R                  44$ rG   )rP   r$  r  r  rj   s    r,   r  Label.__reduce__  s$    ~~		4==$**EEEr-   c                 .    U R                   R                  $ rG   r  rj   s    r,   r  Label._is_implicitly_boolean  r  r-   c                 .    U R                   R                  $ rG   )r7  r  rj   s    r,   r  Label._allow_label_resolve  s    ||000r-   c                     U $ rG   r^   rj   s    r,   r  Label._order_by_label_element  r  r-   c                 ~    [         R                  " U R                  =(       d    [        U R                  SS 5      5      $ r  )r	   r  r  r%  r  rj   s    r,   r(   
Label.type  s.    ##JJ>'$-->
 	
r-   c                 P    U R                   R                  [        R                  S9$ r  )r  r   r   as_rj   s    r,   r7  Label.element  s    }}''	'>>r-   c                 J    U R                  U R                  R                  US9$ r  )_apply_to_innerr  r   r   s     r,   r   Label.self_group  s"    ##DMM$<$<g#NNr-   c                 L    U R                  U R                  R                  5      $ rG   )r'  r  r   rj   s    r,   r   Label._negate	  s    ##DMM$9$9::r-   c                 n    U" U0 UD6nX@R                   La  [        U R                  X@R                  S9$ U $ )Nr!   )r  r  r$  r  )rJ   fnr  rV   sub_elements        r,   r'  Label._apply_to_inner  s3    #nnmm+KzzBBKr-   c                 .    U R                   R                  $ rG   )r7  r  rj   s    r,   r  Label.primary_key  s    ||'''r-   c                 .    U R                   R                  $ rG   )r7  r  rj   s    r,   r  Label.foreign_keys  s    ||(((r-   Fc                    U R                  5         U" U R                  40 UD6U l        U(       aY  [        R                  [	        U 5      [        U R                  SS5      5      U l        U R                  =U l        =U l	        U l
        g g )Nr$  r  )_reset_memoizationsr  r  r  r   r%  r7  r$  r;   r   r  )rJ   cloneanonymize_labelsrV   s       r,   _copy_internalsLabel._copy_internals  sp      "dmm2r2(774'$,,?DI >BYYFDHFt~(:	 r-   c                 .    U R                   R                  $ rG   rj  rj   s    r,   r   Label._from_objects$  rl  r-   c           	         U(       d  U R                   OUnU R                  R                  UUS[        U[        5      S9u  pEX@R                   :w  aB  [        U R                   [
        5      (       d#  [        R                  " SU R                   -  5      eUR                  Ul        UR                  R                  U 5        U R                  b  U R                  Ul        U R                  U4$ )NT)r$  disallow_is_literalr  zLabel name %s is being renamed to an anonymous label due to disambiguation which is not supported right now.  Please use unique names for explicit labels.)r$  r7  r  r  _truncated_labelr  r   InvalidRequestErrorrI   rg  r  r  r(   r;   )rJ   r  r$  rV   r;   es         r,   r  Label._make_proxy(  s     $tyy$)) $ *41A B	 * 
 ))Jtyy:J$K$K))' +/))5  (88	

$::!ZZAFxx{r-   )r  rg  r  r  r   r  r;   r$  rG   )"r   r   r   r   r   r   r   r!  r"  r	  r&  r  r  r  r   r  r  r   r  r  r  r  r(   r7  r   r   r'  r  r  r   r7  r   r  r  r^   r-   r,   r  r    sS    N 
"//0	#++,	&778 
"//0	&778
*"XF 
3 3 ##1 $1   

 

 ##? $?O; ( ( ) ) %+U G * *r-   r  c                       \ rS rSrSrSrS r\R                  S 5       r	\
R                  S 5       r\
R                  S 5       r\
R                  S 5       r\
R                  S	 5       rSS
 jrSS jr   SS jrSrg)NamedColumniI  FNc                     [        US5      =(       a    U R                  UR                  :H  =(       d,    [        US5      =(       a    U R                  UR                  :H  $ )Nr$  r!  )r   r$  r!  r|  s     r,   r}  $NamedColumn._compare_name_for_resultM  sD    v&B499

+B 
E8$D)D	
r-   c                 |    [         R                  (       a  U R                  $ U R                  R                  SS5      $ r   )r   r   r$  r   rj   s    r,   r   NamedColumn.descriptionR  s+    999999##G-?@@r-   c                     U R                   nU(       a   XR                  :w  a  U R                  U5      $ U R                  $ )ztable qualified label based on column key.

for table-bound columns this is <tablename>_<column key/proxy key>;

all other expressions it resolves to key/proxy key.

)r  r$  _gen_tq_labelr   )rJ   r  s     r,   r  NamedColumn._tq_key_labelY  s4     OO	ii/%%i00>>!r-   c                 8    U R                  U R                  5      $ )ztable qualified label based on column name.

for table-bound columns this is <tablename>_<columnname>; all other
expressions it resolves to .name.

rH  r$  rj   s    r,   r   NamedColumn._tq_labelh  s     !!$)),,r-   c                     gr  r^   rj   s    r,   r  +NamedColumn._render_label_in_columns_clauser  r  r-   c                     U R                   $ rG   )r$  rj   s    r,   r&  NamedColumn._non_anon_labelv  s    yyr-   c                     U$ rG   r^   )rJ   r$  dedupe_on_keys      r,   rH  NamedColumn._gen_tq_labelz  r  r-   c           
      H    [        U R                  UUU R                  USUS9$ )NT)rX  rY  r"   r8   rZ  )r:   r;   r(   r[  s        r,   r]  NamedColumn._bind_param}  s,    HH"*"ii
 	
r-   c                    [        U(       a8  [        R                  " [        R                  U=(       d    U R
                  5      OU=(       d    U R
                  U R                  USS9nUR                  Ul        Uc  U R                  Ul        U /Ul	        UR                  b4  UR                  R                  R                  UR                  5      Ul
        UR                  U4$ )NFr"   r  r  )r  r   r#   r   r  r$  r(   rI   r;   rg  rU   r  r   )rJ   r  r$  r  r<  rV   rX   s          r,   r  NamedColumn._make_proxy  s     " U55t7HtyyI#$))))"
 (88<HHAEV
"".'44<<@@GANuuaxr-   r^   Tr   NFF)r   r   r   r   r  tabler}  r   r  r   r   r  r  r   r  r&  rH  r]  r  r  r^   r-   r,   rB  rB  I  s    JE

 
A A ##" $" ##- $- ## $ ## $	
 !!r-   rB  c                   n  ^  \ rS rSrSrSrSrSrS\R                  4S\R                  4S\R                  4S	\R                  4/rS=r=r=rrSr\S
 5       rSS jrSS jr\U 4S j5       rSU 4S jjr\R4                  S 5       r\R4                  S 5       r\S 5       rS rSS jr   SS jr Sr!U =r"$ )r  i  av  Represents a column expression from any textual string.

The :class:`.ColumnClause`, a lightweight analogue to the
:class:`_schema.Column` class, is typically invoked using the
:func:`_expression.column` function, as in::

    from sqlalchemy import column

    id, name = column("id"), column("name")
    stmt = select(id, name).select_from("user")

The above statement would produce SQL like::

    SELECT id, name FROM user

:class:`.ColumnClause` is the immediate superclass of the schema-specific
: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:`_schema.Column` does,
so in that sense is a "lightweight"
version of :class:`_schema.Column`.

Full details on :class:`.ColumnClause` usage is at
:func:`_expression.column`.

.. seealso::

    :func:`_expression.column`

    :class:`_schema.Column`

NFrR  r$  r(   r[  r  c                 F    U R                   =(       a    U R                  S:H  $ r9  )r  r$  rj   s    r,   r  ColumnClause._is_star  s    3499#33r-   c                 n    U=U l         U l        X@l        [        R                  " U5      U l        X0l        g)a+  Produce a :class:`.ColumnClause` object.

The :class:`.ColumnClause` is a lightweight analogue to the
:class:`_schema.Column` class.  The :func:`_expression.column`
function can
be invoked with just a name alone, as in::

    from sqlalchemy import column

    id, name = column("id"), column("name")
    stmt = select(id, name).select_from("user")

The above statement would produce SQL like::

    SELECT id, name FROM user

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

    id, name = column("id"), column("name")
    stmt = select(id, name).select_from("user")

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:`_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:`_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:`_schema.Table`
) to produce
a working table construct with minimal boilerplate::

    from sqlalchemy import table, column, select

    user = table("user",
            column("id"),
            column("name"),
            column("description"),
    )

    stmt = select(user.c.description).where(user.c.name == 'wendy')

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:`_schema.Table` counterpart.

.. 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
  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:`_expression.literal_column()` function essentially invokes
  :func:`_expression.column` while passing ``is_literal=True``.

.. seealso::

    :class:`_schema.Column`

    :func:`_expression.literal_column`

    :func:`.table`

    :func:`_expression.text`

    :ref:`tutorial_select_arbitrary_text`

N)r;   r$  r[  r	   r  r(   r  )rJ   r1  r"   r  r  s        r,   r  ColumnClause.__init__  s/    x  $#49 
((/	$r-   c                     / $ rG   r^   )rJ   column_tablesrV   s      r,   r  ColumnClause.get_childrenB  s	     	r-   c                 f   > U R                   b  U R                   R                  $ [        [        U ]  $ rG   )r[  rv   r6  r  r7  s    r,   rv   ColumnClause.entity_namespaceH  s*    ::!::...t==r-   c                   > U(       ai  U R                   b\  U R                   R                  (       aA  UR                  S5      nU" U R                   40 UD6nUR                  R	                  U 5      nU$ [
        [        U ]  " S0 UD6$ )Nr5  r^   )r[  _is_subqueryrz   rX   corresponding_columnr6  r  r   )rJ   r   rV   r5  r[  newrP   s         r,   r   ColumnClause._cloneO  sk     

&

''FF7OE$**++E''..t4CJ\4/5"55r-   c                 *    U R                   nUb  U/$ / $ rG   r[  )rJ   ts     r,   r   ColumnClause._from_objects\  s    JJ=3JIr-   c                     U R                   S L$ rG   rl  rj   s    r,   r  ,ColumnClause._render_label_in_columns_claused  s    zz%%r-   c                 6    U R                  U R                  SS9$ )NF)rR  rK  rj   s    r,   
_ddl_labelColumnClause._ddl_labelh  s    !!$))5!AAr-   c                 :   U R                   (       d  U R                  bz  U R                  R                  (       d_  [        US5      (       aN  [	        U[
        5      (       a  UR                   (       d(  UR                  b  UR                  R                  (       a_  [        US5      =(       a    U R                  UR                  :H  =(       d,    [        US5      =(       a    U R                  UR                  :H  $ UR                  R                  U R                  5      $ )Nrk  r$  r   )
r  r[  r  r   r  r  r$  r   rk  rw  r|  s     r,   r}  %ColumnClause._compare_name_for_resultl  s    OOzz!zz%%5+..5,//$${{*{{.. E6*FtyyEJJ/F {+ 6NNeoo5
 ??//??r-   c                 <   U R                   nU R                  (       a  gUGby  UR                  (       Gag  [        USS5      (       a3  UR                  R                  SS5      S-   UR                  -   S-   U-   nOUR                  S-   U-   n[        USS5      b=  [        U[        5      (       a  UR                  Ul	        Od[        XAR                  5      nON[        UR                  SS5      b6  [        U[        5      (       a   e[        XCR                  R                  5      nU(       aK  XCR                  ;   a<  UnSnXSR                  ;   a'  US-   [        U5      -   nUS-  nXSR                  ;   a  M'  Un[        R                  " [        R                  U5      $ U$ )zgenerate table-qualified label

for a table-bound column this is <tablename>_<columnname>.

used primarily for LABEL_STYLE_TABLENAME_PLUS_COL
as well as the .columns collection on a Join object.

Nschema.r  r  r   )r[  r  named_with_columnr%  rw  replacer$  r  r  r  rX   r   r   r#   r   r  )rJ   r$  rR  rm  r  r!  counters          r,   rH  ColumnClause._gen_tq_label  sU    JJ??]q222q(D))((c2S8166ACG$Nt+ tWd+7e[11"&**EK'zz:E$/; &e[9999#E66<<8 CC<"FG CC-!&s7|!;1 !CC- #E##E$<$<eDD Kr-   c                 J   U(       + =(       a,    U R                   =(       a    US L =(       d    X R                  :H  nU R                  U(       a8  [        R                  " [
        R                  U=(       d    U R                  5      OU=(       d    U R                  U R                  UUS9nUR                  Ul        Uc  U R                  Ul	        U /Ul
        UR                  b4  UR                  R                  R                  UR                  5      Ul        UR                  U4$ )NrW  )r  r$  rk   r   r#   r   r  r(   rI   r;   rg  rU   r  r   )rJ   r  r$  r  r<  rV   r  rX   s           r,   r  ColumnClause._make_proxy  s     $# 
  %99$ 	 " U55t7HtyyI#$))))"!  
 (88<HHAEV
"".'44<<@@GANuuaxr-   )r  r;   r$  r[  r(   )NFNr   rY  rZ  )#r   r   r   r   r   r[  r  r   r   r!  r"  r	  r%  r&  onupdaterE   server_defaultserver_onupdate_is_multiparam_columnr  r  r  r  rv   r   r   r  r   r  rr  r}  rH  r  r  r  ri   s   @r,   r  r    s   #J EJN 
"//0	"**+	#445	(334	 =A@H@w@/!4 4_%B > >6 ## $ ##& $& B B@,2n !!& &r-   r  c                       \ rS rSrSrS\R                  4S\R                  4S\R                  4/r	S r
\4S jr\S 5       rS	rg
)TableValuedColumni  table_valued_columnr$  r(   scalar_aliasc                 L    Xl         UR                  =U l        U l        X l        g rG   )r  r$  r;   r(   )rJ   r  r"   s      r,   r  TableValuedColumn.__init__  s!    (+00049	r-   c                 x    U" U R                   40 UD6U l         U R                   R                  =U l        U l        g rG   )r  r$  r;   )rJ   r5  rV   s      r,   r7  !TableValuedColumn._copy_internals  s4    !$"3"3:r:#0055549r-   c                     U R                   /$ rG   )r  rj   s    r,   r   TableValuedColumn._from_objects  s    !!""r-   )r;   r$  r  r(   N)r   r   r   r   r   r   r!  r"  r	  r&  r  r   r7  r  r   r  r^   r-   r,   r  r    sa    *N 
"//0	"**+	*;;<
 %+ 6 # #r-   r  c                   <    \ rS rSrSrS\R                  4/rS rSr	g)r&   i  r*   c                     Xl         g rG   r*   )rJ   r*   s     r,   r  CollationClause.__init__  s    "r-   r  N)
r   r   r   r   r   r   rd  r&  r  r  r^   r-   r,   r&   r&     s!     N'):)D)DEF#r-   r&   c                   X    \ rS rSrSr\R                  R                  SS05      rS rSr	g)_IdentifiedClausei  
identifiedr2  Fc                     Xl         g rG   ident)rJ   r  s     r,   r  _IdentifiedClause.__init__  s    
r-   r  N)
r   r   r   r   r   r   rg  rh  r  r  r^   r-   r,   r  r    s+    !N#66<<	ur-   r  c                       \ rS rSrSrSrSrg)SavepointClausei
  	savepointFr^   Nr   r   r   r   r   r  r  r^   r-   r,   r  r  
  s     NMr-   r  c                       \ rS rSrSrSrSrg)RollbackToSavepointClausei  rollback_to_savepointFr^   Nr  r^   r-   r,   r  r    s    ,NMr-   r  c                       \ rS rSrSrSrSrg)ReleaseSavepointClausei  release_savepointFr^   Nr  r^   r-   r,   r  r    s    (NMr-   r  c                   H   ^  \ rS rSrSrSrU 4S jrS rS rS r	S r
S	rU =r$ )
r  i  aB  Represent a SQL identifier combined with quoting preferences.

:class:`.quoted_name` is a Python unicode/str subclass which
represents a particular identifier name along with a
``quote`` flag.  This ``quote`` flag, when set to
``True`` or ``False``, overrides automatic quoting behavior
for this identifier in order to either unconditionally quote
or to not quote the name.  If left at its default of ``None``,
quoting behavior is applied to the identifier on a per-backend basis
based on an examination of the token itself.

A :class:`.quoted_name` object with ``quote=True`` is also
prevented from being modified in the case of a so-called
"name normalize" option.  Certain database backends, such as
Oracle, Firebird, and DB2 "normalize" case-insensitive names
as uppercase.  The SQLAlchemy dialects for these backends
convert from SQLAlchemy's lower-case-means-insensitive convention
to the upper-case-means-insensitive conventions of those backends.
The ``quote=True`` flag here will prevent this conversion from occurring
to support an identifier that's quoted as all lower case against
such a backend.

The :class:`.quoted_name` object is normally created automatically
when specifying the name for key schema constructs such as
: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.Engine.has_table`
method with
an unconditionally quoted name::

    from sqlalchemy import create_engine
    from sqlalchemy import inspect
    from sqlalchemy.sql import quoted_name

    engine = create_engine("oracle+cx_oracle://some_dsn")
    print(inspect(engine).has_table(quoted_name("some_table", True)))

The above logic will run the "has table" logic against the Oracle backend,
passing the name exactly as ``"some_table"`` without converting to
upper case.

.. versionadded:: 0.9.0

.. versionchanged:: 1.2 The :class:`.quoted_name` construct is now
   importable from ``sqlalchemy.sql``, in addition to the previous
   location of ``sqlalchemy.sql.elements``.

)r  r  r  c                    > Uc  g [        X5      (       a  Ub  UR                  U:X  a  U$ [        [        U ]  X5      nX#l        U$ rG   )r  r  r6  r  rQ   )rH  r5   r  rJ   rP   s       r,   rQ   quoted_name.__new__N  sH    = ##MU[[E1L[#.s:
r-   c                 R    [         [        R                  " U 5      U R                  44$ rG   )r  r   	text_typer  rj   s    r,   r  quoted_name.__reduce___  s    T^^D14::>>>r-   c                 p    U R                   (       a  U $ [        R                  " U 5      R                  5       $ rG   )r  r   r  r  rj   s    r,   _memoized_method_lower"quoted_name._memoized_method_lowerb  &    ::K>>$'--//r-   c                 p    U R                   (       a  U $ [        R                  " U 5      R                  5       $ rG   )r  r   r  r  rj   s    r,   _memoized_method_upper"quoted_name._memoized_method_upperh  r  r-   c                     [         R                  (       a=  U R                  SS5      n[         R                  (       d  UR                  S5      nSU-  $ [        R                  U 5      $ )Nr   r   z'%s')r   py2kr   decoder   r   )rJ   backslasheds     r,   r   quoted_name.__repr__n  sK    99++g/ABK99)009K''<<%%r-   )r  )r   r   r   r   r   	__slots__rQ   r  r  r  r   r  r  ri   s   @r,   r  r    s.    0d *I"?00& &r-   r  c                 b    [         R                  " 5       n[        U 0 SUR                  05        U$ )z2locate Column objects within the given expression.rR  )r   rn   r   ro   )r@   rV  s     r,   _find_columnsr  x  s*     ??DVR(DHH-.Kr-   c                     U  H,  nUR                   R                  (       a  M   UR                   s  $    [        R                  $ rG   )r(   r  r	   r;  )argsas     r,   _type_from_argsr    s0    vv~~~66M     r-   c           
          U R                  XS9nUc8  [        R                  " SU< S[        USS 5      < SU R                  < S35      eU$ )N)require_embeddedzGiven column 'z', attached to table 'r[  z7', failed to locate a corresponding column from table '')rh  r   r>  r%  r   )
fromclauserR  r  rX   s       r,   _corresponding_column_or_errorr    sY    '' 	( 	A 	y%% wvw5z7M7MO
 	

 Hr-   c                      ^  \ rS rSrS rU 4S jr\R                  S 5       r\R                  S 5       r	\R                  S 5       r
\R                  S 5       r\R                  S 5       rS	rU =r$ )
AnnotatedColumnElementi  c                    [         R                  " XU5        S H  nU R                  R                  US 5        M!     S H=  nU R                  R	                  US5      b  M"  U R                  R                  U5        M?     g )NrD  r  r  r   r&  )r$  r;   r[  F)r
   r  rR   rz   r   )rJ   r7  rK   r  s       r,   r  AnnotatedColumnElement.__init__  si    4&1
D MMdD)
 -D}}  u-5!!$' -r-   c                 x   > [         [        U ]  U5      nS H  nUR                  R	                  US 5        M!     U$ )Nr  )r6  r  _with_annotationsrR   rz   )rJ   rK   r5  r  rP   s       r,   r  (AnnotatedColumnElement._with_annotations  s>    ,dEfM
D NNtT*
 r-   c                 .    U R                   R                  $ )z'pull 'name' from parent, if not present)_Annotated__elementr$  rj   s    r,   r$  AnnotatedColumnElement.name  s     '',,,r-   c                 .    U R                   R                  $ )z(pull 'table' from parent, if not present)r  r[  rj   s    r,   r[  AnnotatedColumnElement.table  s     ''---r-   c                 .    U R                   R                  $ )z&pull 'key' from parent, if not present)r  r;   rj   s    r,   r;   AnnotatedColumnElement.key  s     ''+++r-   c                 .    U R                   R                  $ rG   )r  inforj   s    r,   r  AnnotatedColumnElement.info  s    '',,,r-   c                 .    U R                   R                  $ rG   )r  r  rj   s    r,   r  'AnnotatedColumnElement._anon_name_label  s    ''888r-   r^   )r   r   r   r   r  r  r   r  r$  r[  r;   r  r  r  r  ri   s   @r,   r  r    s    (
 
- - 
. . 
, , 
- - 
9 9r-   r  c                   @   ^  \ rS rSrSrSrSU 4S jjrS rS rSr	U =r
$ )r=  i  zRA unicode subclass used to identify symbolic "
"names that may require truncation.r^   c                 F   > [        USU5      n[        [        U ]  XU5      $ )Nr  )r%  r6  r=  rQ   )rH  r5   r  rP   s      r,   rQ   _truncated_label.__new__  s&    w.%s3CFFr-   c                 ^    U R                   [        R                  " U 5      U R                  44$ rG   )rP   r   r  r  rj   s    r,   r  _truncated_label.__reduce__  s#    ~~t 4djjAAAr-   c                     U $ rG   r^   rJ   map_s     r,   	apply_map_truncated_label.apply_map  r  r-   rG   )r   r   r   r   r   r  rQ   r  r  r  r  ri   s   @r,   r=  r=    s%    + IG
B r-   r=  c                       \ rS rSrSrSrSrg)convi  a  Mark a string indicating that a name has already been converted
by a naming convention.

This is a string subclass that indicates a name that should not be
subject to any further naming conventions.

E.g. when we create a :class:`.Constraint` using a naming convention
as follows::

    m = MetaData(naming_convention={
        "ck": "ck_%(table_name)s_%(constraint_name)s"
    })
    t = Table('t', m, Column('x', Integer),
                    CheckConstraint('x > 5', name='x5'))

The name of the above constraint will be rendered as ``"ck_t_x5"``.
That is, the existing name ``x5`` is used in the naming convention as the
``constraint_name`` token.

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
use this explicitly as follows::


    m = MetaData(naming_convention={
        "ck": "ck_%(table_name)s_%(constraint_name)s"
    })
    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
name here is final, and the name will render as ``"ck_t_x5"`` and not
``"ck_t_ck_t_x5"``

.. versionadded:: 0.9.4

.. seealso::

    :ref:`constraint_naming_conventions`

r^   N)r   r   r   r   r   r  r  r^   r-   r,   r  r    s    *X Ir-   r  	NONE_NAMEc                   D    \ rS rSrSrSr\ S	S j5       rS rS r	S r
Srg)
r  i  z@A unicode subclass used to identify anonymously
generated names.r^   Nc                     [         R                  " SSU5      nU(       a  UR                  S5      nSXR                  SS5      4-  nU(       a  U< U< 3n[	        U5      $ )Nz[%\(\) \$]+r  z
%%(%d %s)s%%%)re  rD  striprz  r  )rH  r  bodyr  r  r  s         r,   r  _anonymous_label.safe_construct  sV     vvnc40::c?Dll3&=>>-u5E&&r-   c                 *   SU;   a<  [        U[        5      (       d'  [        R                  " U5      R	                  SS5      nO[        R                  " U5      n[        [        [        R                  R                  X5      U R                  5      5      $ Nr  r  r  r  r   r  rz  r  __add__r  r|  s     r,   r  _anonymous_label.__add__-  sm    %<
52B C CNN5)11#t<ENN5)E&&t3


 	
r-   c                 *   SU;   a<  [        U[        5      (       d'  [        R                  " U5      R	                  SS5      nO[        R                  " U5      n[        [        [        R                  R                  X5      U R                  5      5      $ r  r  r|  s     r,   __radd___anonymous_label.__radd__:  sm    %<
52B C CNN5)11#t<ENN5)E&&u3


 	
r-   c                 T    U R                   b  [        X-  U R                   5      $ X-  $ rG   )r  r  r  s     r,   r  _anonymous_label.apply_mapG  s)    ::!t{DJJ77 ;r-   r   )r   r   r   r   r   r  rj  r  r  r  r  r  r^   r-   r,   r  r    s2     I<A' '$

r-   r  r   rG   )wr   
__future__r   r  r   re  r  r   r   r   r   r	   
annotationr
   r   baser   r   r   r   r   r   r   r   r   r   r   r   visitorsr   r   r   r   r   r   r   r'   r0   r6   r<   rA   _self_inspectsSQLRolerC   ColumnArgumentOrKeyRoleStatementOptionRoler  BinaryElementRoleOrderByRoleColumnsClauseRoleLimitOffsetRoleDMLColumnRoleDDLConstraintColumnRoleDDLExpressionRoleColumnOperatorsr  r   r  InElementRoler:   r(  FromClauseRoleSelectStatementRoler.  ConstExprRolerm  _create_singletonrv  r~  r  r  r)  r*  r  r  r  r  r  r,  r5  r@  r   rr  r.  r%   r  r  r  r3  symbolr  r  r  r  r   LabeledColumnExprRoler  rB  DDLReferredColumnRoleStrAsPlainColumnRoler  r  r&   r  r  r  r  MemoizedSlotsr  r  r  r  r  r  r=  r  
_NONE_NAME_generated_labelr  r^   r-   r,   <module>r     s  
 (   	      ! 3       " # . ( +   % '  !   25GpH,
PP n	MMn nbf5	!!								!!	f5R==F ==@t
E'' t
n P	!!								Pfe11= .    6 3 3] 6r    >u22M >B    Y				Yxz(
M z(z XJ XvW
= W
t!<Hb - bJB& BJ6'm 6'r} 2
5} 
5cm cL	X
/ X
vG% G4f;} f;R'M 'T& 	'] 	'0"~} 0"f ++/0O,F
= F
Rl
- l
^~
] ~
BZE'' ZzU- Up{			{|	# #.#m #
M ' 
 1 
. 
\&$$$dnn \&~!
09Y 09f{ $- -` [[%
 D $ 9' 9r-   