
    +h                       d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 dd	lm
Z
 dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddlm!Z! ddlm"Z" dd lm#Z# dd!l$m%Z% dd"l$m&Z& dd#l$m'Z' dd$l$m(Z( dd%l$m)Z) dd&l$m*Z* dd'l$m+Z+ dd(l$m,Z, dd)l$m-Z- dd*l$m.Z. dd+l$m/Z/ dd,l$m0Z0 dd-lm1Z1 d.d/lm2Z2 d.d0lm3Z3 d.d1l4m5Z5  G d2 d3e'      Z6 e3jn                  d4d5      d6        Z8 G d7 d8ejr                  e)      Z: G d9 d:e:      Z; G d; d<e<      Z= G d= d>e<      Z> G d? d@e<      Z? G dA dBej                  e;      ZA e3j                  dCdD      ZC e3j                  dEdF      ZD e3j                  dGdH      ZEeEZF	  G dI dJej                  eA      ZH G dK dLe<      ZI G dM dNeIeA      ZJ G dO dPej                  eJ      ZK G dQ dReK      ZL G dS dTeJ      ZM G dU dVeJ      ZN G dW dXej                  ej                  ee=e>eJ      ZP G dY dZej                        ZR G d[ d\eJ      ZS G d] d^e,eA      ZT G d_ d`ej                  e!eA      ZU G da dbe)      ZV G dc ddeeA      ZW G de dfej                  ej                  ej                  ej                  eReee;
      Z\ G dg dhe,e\      Z] G di dje<      Z^ G dk dle^e\      Z_ ej                  dmdn       G do dpe             Za G dq dree_      Zb G ds dte<      Zc ej                  dmdu       G dv dwe3j                  e             Ze G dx dye<      Zf G dz d{e	j                  e	j                  ej                        Zj G d| d}e=e>e?eecefe_	      Zk G d~ dej                  ee-      Zl G d de0      Zm G d de\      ZnenZo	  G d de      Zpy)ztThe :class:`_expression.FromClause` class of SQL expression elements,
representing
SQL tables and derived rowsets.

    N)
attrgetter   )	coercions)	operators)roles)
traversals)type_api)visitors)	Annotated)SupportsCloneAnnotations)_clone)_cloned_difference)_cloned_intersection)_entity_namespace_key)_expand_cloned_from_objects)_generative)_select_iterables)CacheableOptions)ColumnCollection)	ColumnSet)CompileState)DedupeColumnCollection)
Executable)
Generative)HasCompileState)HasMemoized)	Immutable)prefix_anon_map)_document_text_coercion)_anonymous_label)and_)BindParameter)BooleanClauseList)ClauseElement)
ClauseList)ColumnClause)GroupedElement)Grouping)literal_column)TableValuedColumn)UnaryExpression)InternalTraversal   )exc)util)inspectc                        e Zd ZdZed        Zy)_OffsetLimitParamTc                     | j                   S N)effective_valueselfs    L/var/www/html/venv/lib/python3.12/site-packages/sqlalchemy/sql/selectable.py_limit_offset_valuez%_OffsetLimitParam._limit_offset_valueC   s    ###    N)__name__
__module____qualname__inherit_cachepropertyr;    r<   r:   r4   r4   @   s    M$ $r<   r4   1.4zzThe standalone :func:`.subquery` function is deprecated and will be removed in a future release.  Use select().subquery().c                 J    t        j                  |i |j                  |       S )a  Return an :class:`.Subquery` object derived
    from a :class:`_expression.Select`.

    :param alias: the alias name for the subquery

    :param \*args, \**kwargs:  all other arguments are passed through to the
     :func:`_expression.select` function.

    )Selectcreate_legacy_selectsubquery)aliasargskwargss      r:   rG   rG   H   s%     &&77@@GGr<   c                   P    e Zd ZdZdZdZdZdZed        Z	ed        Z
ed        Zy)ReturnsRowsa  The base-most class for Core constructs that have some concept of
    columns that can represent rows.

    While the SELECT statement and TABLE are the primary things we think
    of in this category,  DML like INSERT, UPDATE and DELETE can also specify
    RETURNING which means they can be used in CTEs and other forms, and
    PostgreSQL has functions that return rows also.

    .. versionadded:: 1.4

    TFc                     | S r6   rB   r8   s    r:   
selectablezReturnsRows.selectablen   s    r<   c                     t               )aE  A sequence of column expression objects that represents the
        "selected" columns of this :class:`_expression.ReturnsRows`.

        This is typically equivalent to .exported_columns except it is
        delivered in the form of a straight sequence and not  keyed
        :class:`_expression.ColumnCollection`.

        NotImplementedErrorr8   s    r:   _all_selected_columnsz!ReturnsRows._all_selected_columnsr   s     "##r<   c                     t               )a  A :class:`_expression.ColumnCollection`
        that represents the "exported"
        columns of this :class:`_expression.ReturnsRows`.

        The "exported" columns represent the collection of
        :class:`_expression.ColumnElement`
        expressions that are rendered by this SQL
        construct.   There are primary varieties which are the
        "FROM clause columns" of a FROM clause, such as a table, join,
        or subquery, the "SELECTed columns", which are the columns in
        the "columns clause" of a SELECT statement, and the RETURNING
        columns in a DML statement..

        .. versionadded:: 1.4

        .. seealso::

            :attr:`_expression.FromClause.exported_columns`

            :attr:`_expression.SelectBase.exported_columns`
        rP   r8   s    r:   exported_columnszReturnsRows.exported_columns~   s    0 "##r<   N)r=   r>   r?   __doc___is_returns_rows_is_from_clause_is_select_statement_is_lateralrA   rN   rR   rT   rB   r<   r:   rL   rL   Z   s[    
  O K  	$ 	$ $ $r<   rL   c                       e Zd ZdZdZdZd ZddZ ej                  dd	       ej                  d
      d               ZddZy)
Selectablez!Mark a class as being selectable.rN   Tc                     t               r6   rP   r9   columns     r:   _refresh_for_new_columnz"Selectable._refresh_for_new_column       !##r<   Nc                 .    t         j                  | |      S aZ  Return a LATERAL alias of this :class:`_expression.Selectable`.

        The return value is the :class:`_expression.Lateral` construct also
        provided by the top-level :func:`_expression.lateral` function.

        .. versionadded:: 1.1

        .. seealso::

            :ref:`tutorial_lateral_correlation` -  overview of usage.

        )Lateral
_constructr9   names     r:   lateralzSelectable.lateral   s     !!$--r<   rC   zThe :meth:`.Selectable.replace_selectable` method is deprecated, and will be removed in a future release.  Similar functionality is available via the sqlalchemy.sql.visitors module.)messagesqlalchemy.sql.utilc                 r    t         j                  j                  j                  |      j	                  |       S )zReplace all occurrences of :class:`_expression.FromClause`
        'old' with the given :class:`_expression.Alias`
        object, returning a copy of this :class:`_expression.FromClause`.

        )r1   	preloadedsql_utilClauseAdaptertraverse)r9   oldrH   s      r:   replace_selectablezSelectable.replace_selectable   s*     ~~&&44U;DDTJJr<   c                 :    | j                   j                  ||      S )a  Given a :class:`_expression.ColumnElement`, return the exported
        :class:`_expression.ColumnElement` object from the
        :attr:`_expression.Selectable.exported_columns`
        collection of this :class:`_expression.Selectable`
        which corresponds to that
        original :class:`_expression.ColumnElement` via a common ancestor
        column.

        :param column: the target :class:`_expression.ColumnElement`
                      to be matched.

        :param require_embedded: only return corresponding columns for
         the given :class:`_expression.ColumnElement`, if the given
         :class:`_expression.ColumnElement`
         is actually present within a sub-element
         of this :class:`_expression.Selectable`.
         Normally the column will match if
         it merely shares a common ancestor with one of the exported
         columns of this :class:`_expression.Selectable`.

        .. seealso::

            :attr:`_expression.Selectable.exported_columns` - the
            :class:`_expression.ColumnCollection`
            that is used for the operation.

            :meth:`_expression.ColumnCollection.corresponding_column`
            - implementation
            method.

        )rT   corresponding_column)r9   r^   require_embeddeds      r:   rr   zSelectable.corresponding_column   s$    B $$99$
 	
r<   r6   F)r=   r>   r?   rU   __visit_name__is_selectabler_   rg   r1   
deprecatedpreload_modulerp   rr   rB   r<   r:   r[   r[      s`    +!NM$. T__M T./K 0K#
r<   r[   c                   `    e Zd ZdZdej
                  fgZe eddd      d               Z	d	dZ
y)
HasPrefixesrB   	_prefixesexprz+:meth:`_expression.HasPrefixes.prefix_with`z*:paramref:`.HasPrefixes.prefix_with.*expr`c                     |j                  dd      }|r't        j                  ddj                  |      z        | j	                  ||       y)a  Add one or more expressions following the statement keyword, i.e.
        SELECT, INSERT, UPDATE, or DELETE. Generative.

        This is used to support backend-specific prefix keywords such as those
        provided by MySQL.

        E.g.::

            stmt = table.insert().prefix_with("LOW_PRIORITY", dialect="mysql")

            # MySQL 5.7 optimizer hints
            stmt = select(table).prefix_with(
                "/*+ BKA(t1) */", dialect="mysql")

        Multiple prefixes can be specified by multiple calls
        to :meth:`_expression.HasPrefixes.prefix_with`.

        :param \*expr: textual or :class:`_expression.ClauseElement`
         construct which
         will be rendered following the INSERT, UPDATE, or DELETE
         keyword.
        :param \**kw: A single keyword 'dialect' is accepted.  This is an
         optional string dialect name which will
         limit rendering of this prefix to only that dialect.

        dialectNUnsupported argument(s): %s,)popr0   ArgumentErrorjoin_setup_prefixesr9   r|   kwr~   s       r:   prefix_withzHasPrefixes.prefix_with   sM    B &&D)##-<  	T7+r<   Nc           
          | j                   t        |D cg c](  }t        j                  t        j
                  |      |f* c}      z   | _         y c c}w r6   )r{   tupler   expectr   StatementOptionRole)r9   prefixesr~   ps       r:   r   zHasPrefixes._setup_prefixes  N    % " !!%";";Q?I+
 
   -A
r6   )r=   r>   r?   r{   r.   dp_prefix_sequence _has_prefixes_traverse_internalsr   r!   r   r   rB   r<   r:   rz   rz      sP    I 
'::;($ 54
 ,  ,D
r<   rz   c                   `    e Zd ZdZdej
                  fgZe eddd      d               Z	d	dZ
y)
HasSuffixesrB   	_suffixesr|   z+:meth:`_expression.HasSuffixes.suffix_with`z*:paramref:`.HasSuffixes.suffix_with.*expr`c                     |j                  dd      }|r't        j                  ddj                  |      z        | j	                  ||       y)a  Add one or more expressions following the statement as a whole.

        This is used to support backend-specific suffix keywords on
        certain constructs.

        E.g.::

            stmt = select(col1, col2).cte().suffix_with(
                "cycle empno set y_cycle to 1 default 0", dialect="oracle")

        Multiple suffixes can be specified by multiple calls
        to :meth:`_expression.HasSuffixes.suffix_with`.

        :param \*expr: textual or :class:`_expression.ClauseElement`
         construct which
         will be rendered following the target clause.
        :param \**kw: A single keyword 'dialect' is accepted.  This is an
         optional string dialect name which will
         limit rendering of this suffix to only that dialect.

        r~   Nr   r   )r   r0   r   r   _setup_suffixesr   s       r:   suffix_withzHasSuffixes.suffix_with&  sL    8 &&D)##-<  	T7+r<   Nc           
          | j                   t        |D cg c](  }t        j                  t        j
                  |      |f* c}      z   | _         y c c}w r6   )r   r   r   r   r   r   )r9   suffixesr~   r   s       r:   r   zHasSuffixes._setup_suffixesI  r   r   r6   )r=   r>   r?   r   r.   r    _has_suffixes_traverse_internalsr   r!   r   r   rB   r<   r:   r   r     sO    I 
'::;($ 54
, ,:
r<   r   c                       e Zd Z ej                         ZdZdej                  fdej                  fgZ
ddZedd       Zy)HasHintsrB   _statement_hints_hintsc                 (    | j                  d||      S )a  Add a statement hint to this :class:`_expression.Select` or
        other selectable object.

        This method is similar to :meth:`_expression.Select.with_hint`
        except that
        it does not require an individual table, and instead applies to the
        statement as a whole.

        Hints here are specific to the backend database and may include
        directives such as isolation levels, file directives, fetch directives,
        etc.

        .. versionadded:: 1.0.0

        .. seealso::

            :meth:`_expression.Select.with_hint`

            :meth:`_expression.Select.prefix_with` - generic SELECT prefixing
            which also can suit some database-specific HINT syntaxes such as
            MySQL optimizer hints

        N)	with_hint)r9   textdialect_names      r:   with_statement_hintzHasHints.with_statement_hint[  s    0 ~~dD,77r<   c                     || xj                   ||ffz  c_         y| j                  j                  t        j                  t
        j                  |      |f|i      | _        y)a  Add an indexing or other executional context hint for the given
        selectable to this :class:`_expression.Select` or other selectable
        object.

        The text of the hint is rendered in the appropriate
        location for the database backend in use, relative
        to the given :class:`_schema.Table` or :class:`_expression.Alias`
        passed as the
        ``selectable`` argument. The dialect implementation
        typically uses Python string substitution syntax
        with the token ``%(name)s`` to render the name of
        the table or alias. E.g. when using Oracle, the
        following::

            select(mytable).\
                with_hint(mytable, "index(%(name)s ix_mytable)")

        Would render SQL as::

            select /*+ index(mytable ix_mytable) */ ... from mytable

        The ``dialect_name`` option will limit the rendering of a particular
        hint to a particular backend. Such as, to add hints for both Oracle
        and Sybase simultaneously::

            select(mytable).\
                with_hint(mytable, "index(%(name)s ix_mytable)", 'oracle').\
                with_hint(mytable, "WITH INDEX ix_mytable", 'sybase')

        .. seealso::

            :meth:`_expression.Select.with_statement_hint`

        N)r   r   unionr   r   r   FromClauseRole)r9   rN   r   r   s       r:   r   zHasHints.with_hintu  sd    H !!|T&:%<<!++++ "(()=)=zJ$ 	DKr<   N)*)r=   r>   r?   r1   immutabledictr   r   r.   dp_statement_hint_listdp_table_hint_list_has_hints_traverse_internalsr   r   r   rB   r<   r:   r   r   R  sY    T!F 
.EEF	$778%!
84 - -r<   r   c                      e Zd ZdZdZdZg ZdZ	 dZdZ	dZ
dZ ej                  dd      d"d	       Zd#d
Zd$dZd$dZ ej$                  d      d        Zd%dZd Zd Zed        Zd Zed        Zej6                  d        Zed        Zej6                  d        Zej6                  d        Zd Z  e e!d      d      Z" e e!d            Z#d Z$ed        Z%d Z&d  Z'd$d!Z(y)&
FromClauseaE  Represent an element that can be used within the ``FROM``
    clause of a ``SELECT`` statement.

    The most common forms of :class:`_expression.FromClause` are the
    :class:`_schema.Table` and the :func:`_expression.select` constructs.  Key
    features common to all :class:`_expression.FromClause` objects include:

    * a :attr:`.c` collection, which provides per-name access to a collection
      of :class:`_expression.ColumnElement` objects.
    * a :attr:`.primary_key` attribute, which is a collection of all those
      :class:`_expression.ColumnElement`
      objects that indicate the ``primary_key`` flag.
    * Methods to generate various derivations of a "from" clause, including
      :meth:`_expression.FromClause.alias`,
      :meth:`_expression.FromClause.join`,
      :meth:`_expression.FromClause.select`.


    
fromclauseFNT)2.0zThe :paramref:`_sql.FromClause.select().whereclause` parameter is deprecated and will be removed in version 2.0.  Please make use of the :meth:`.Select.where` method to add WHERE criteria to the SELECT statement.)r   zThe :meth:`_sql.FromClause.select` method will no longer accept keyword arguments in version 2.0.  Please use generative methods from the :class:`_sql.Select` construct in order to apply additional modifications.whereclauserJ   c                 @    |||d<   t        j                  | | gfi |S )aT  Return a SELECT of this :class:`_expression.FromClause`.


        e.g.::

            stmt = some_table.select().where(some_table.c.id == 5)

        :param whereclause: a WHERE clause, equivalent to calling the
         :meth:`_sql.Select.where` method.

        :param \**kwargs: additional keyword arguments are passed to the
         legacy constructor for :class:`_sql.Select` described at
         :meth:`_sql.Select.create_legacy_select`.

        .. seealso::

            :func:`_expression.select` - general purpose
            method which allows for arbitrary column lists.

        r   rE   _create_select_from_fromclauser9   r   rJ   s      r:   selectzFromClause.select  s/    N "$/F=!44TD6LVLLr<   c                      t        | ||||      S )a  Return a :class:`_expression.Join` from this
        :class:`_expression.FromClause`
        to another :class:`FromClause`.

        E.g.::

            from sqlalchemy import join

            j = user_table.join(address_table,
                            user_table.c.id == address_table.c.user_id)
            stmt = select(user_table).select_from(j)

        would emit SQL along the lines of::

            SELECT user.id, user.name FROM user
            JOIN address ON user.id = address.user_id

        :param right: the right side of the join; this is any
         :class:`_expression.FromClause` object such as a
         :class:`_schema.Table` object, and
         may also be a selectable-compatible object such as an ORM-mapped
         class.

        :param onclause: a SQL expression representing the ON clause of the
         join.  If left at ``None``, :meth:`_expression.FromClause.join`
         will attempt to
         join the two tables based on a foreign key relationship.

        :param isouter: if True, render a LEFT OUTER JOIN, instead of JOIN.

        :param full: if True, render a FULL OUTER JOIN, instead of LEFT OUTER
         JOIN.  Implies :paramref:`.FromClause.join.isouter`.

         .. versionadded:: 1.1

        .. seealso::

            :func:`_expression.join` - standalone function

            :class:`_expression.Join` - the type of object produced

        Join)r9   rightonclauseisouterfulls        r:   r   zFromClause.join  s    X D%7D99r<   c                      t        | ||d|      S )a  Return a :class:`_expression.Join` from this
        :class:`_expression.FromClause`
        to another :class:`FromClause`, with the "isouter" flag set to
        True.

        E.g.::

            from sqlalchemy import outerjoin

            j = user_table.outerjoin(address_table,
                            user_table.c.id == address_table.c.user_id)

        The above is equivalent to::

            j = user_table.join(
                address_table,
                user_table.c.id == address_table.c.user_id,
                isouter=True)

        :param right: the right side of the join; this is any
         :class:`_expression.FromClause` object such as a
         :class:`_schema.Table` object, and
         may also be a selectable-compatible object such as an ORM-mapped
         class.

        :param onclause: a SQL expression representing the ON clause of the
         join.  If left at ``None``, :meth:`_expression.FromClause.join`
         will attempt to
         join the two tables based on a foreign key relationship.

        :param full: if True, render a FULL OUTER JOIN, instead of
         LEFT OUTER JOIN.

         .. versionadded:: 1.1

        .. seealso::

            :meth:`_expression.FromClause.join`

            :class:`_expression.Join`

        Tr   )r9   r   r   r   s       r:   	outerjoinzFromClause.outerjoin'  s    X D%466r<   c                 .    t         j                  | |      S )at  Return an alias of this :class:`_expression.FromClause`.

        E.g.::

            a2 = some_table.alias('a2')

        The above code creates an :class:`_expression.Alias`
        object which can be used
        as a FROM clause in any SELECT statement.

        .. seealso::

            :ref:`tutorial_using_aliases`

            :func:`_expression.alias`

        )Aliasrd   r9   rf   flats      r:   rH   zFromClause.aliasU  s    & d++r<   zsqlalchemy.sql.sqltypesc                 6    t        | t        j                        S )aD  Return a :class:`_sql.TableValuedColumn` object for this
        :class:`_expression.FromClause`.

        A :class:`_sql.TableValuedColumn` is a :class:`_sql.ColumnElement` that
        represents a complete row in a table. Support for this construct is
        backend dependent, and is supported in various forms by backends
        such as PostgreSQL, Oracle and SQL Server.

        E.g.::

            >>> from sqlalchemy import select, column, func, table
            >>> a = table("a", column("id"), column("x"), column("y"))
            >>> stmt = select(func.row_to_json(a.table_valued()))
            >>> print(stmt)
            SELECT row_to_json(a) AS row_to_json_1
            FROM a

        .. versionadded:: 1.4.0b2

        .. seealso::

            :ref:`tutorial_functions` - in the :ref:`unified_tutorial`

        )r,   r	   
TABLEVALUEr8   s    r:   table_valuedzFromClause.table_valuedj  s    4 !x':':;;r<   c                 2    t         j                  | |||      S )av  Return a TABLESAMPLE alias of this :class:`_expression.FromClause`.

        The return value is the :class:`_expression.TableSample`
        construct also
        provided by the top-level :func:`_expression.tablesample` function.

        .. versionadded:: 1.1

        .. seealso::

            :func:`_expression.tablesample` - usage guidelines and parameters

        )TableSamplerd   )r9   samplingrf   seeds       r:   tablesamplezFromClause.tablesample  s     %%dHdDAAr<   c                     || j                   v S )zReturn ``True`` if this :class:`_expression.FromClause` is
        'derived' from the given ``FromClause``.

        An example would be an Alias of a Table is derived from that Table.

        )_cloned_setr9   r   s     r:   is_derived_fromzFromClause.is_derived_from  s     T----r<   c                 L    | j                   j                  |j                         S )zReturn ``True`` if this :class:`_expression.FromClause` and
        the other represent the same lexical identity.

        This tests if either one is a copy of the other, or
        if they are the same via annotation identity.

        )r   intersectionr9   others     r:   _is_lexical_equivalentz!FromClause._is_lexical_equivalent  s!     ,,U->->??r<   c                 J    t        | d| j                  j                  dz         S )z|A brief description of this :class:`_expression.FromClause`.

        Used primarily for error message formatting.

        rf   z object)getattr	__class__r=   r8   s    r:   descriptionzFromClause.description  s"     tVT^^%<%<y%HIIr<   c                 b    j                   j                  fd| j                  D               y )Nc              3   @   K   | ]  }|j                          y wr6   _make_proxy).0colr   s     r:   	<genexpr>zAFromClause._generate_fromclause_column_proxies.<locals>.<genexpr>  s      4
,/COOJ'4
   )_columns_populate_separate_keyscr   s    `r:   #_generate_fromclause_column_proxiesz.FromClause._generate_fromclause_column_proxies  s(    33 4
37664
 	
r<   c                     | j                   S )a  A :class:`_expression.ColumnCollection`
        that represents the "exported"
        columns of this :class:`_expression.Selectable`.

        The "exported" columns for a :class:`_expression.FromClause`
        object are synonymous
        with the :attr:`_expression.FromClause.columns` collection.

        .. versionadded:: 1.4

        .. seealso::

            :attr:`_expression.Selectable.exported_columns`

            :attr:`_expression.SelectBase.exported_columns`


        columnsr8   s    r:   rT   zFromClause.exported_columns  s    ( ||r<   c                     d| j                   vr | j                          | j                          | j                  j	                         S )a  A named-based collection of :class:`_expression.ColumnElement`
        objects maintained by this :class:`_expression.FromClause`.

        The :attr:`.columns`, or :attr:`.c` collection, is the gateway
        to the construction of SQL expressions using table-bound or
        other selectable-bound columns::

            select(mytable).where(mytable.c.somecolumn == 5)

        :return: a :class:`.ColumnCollection` object.

        r   )__dict___init_collections_populate_column_collectionr   as_immutabler8   s    r:   r   zFromClause.columns  s;     T]]*""$,,.}}))++r<   c                     | j                   S )a  Return a namespace used for name-based access in SQL expressions.

        This is the namespace that is used to resolve "filter_by()" type
        expressions, such as::

            stmt.filter_by(address='some address')

        It defaults to the ``.c`` collection, however internally it can
        be overridden using the "entity_namespace" annotation to deliver
        alternative results.

        r   r8   s    r:   entity_namespacezFromClause.entity_namespace  s     ||r<   c                 Z    | j                          | j                          | j                  S )ap  Return the iterable collection of :class:`_schema.Column` objects
        which comprise the primary key of this :class:`_selectable.FromClause`.

        For a :class:`_schema.Table` object, this collection is represented
        by the :class:`_schema.PrimaryKeyConstraint` which itself is an
        iterable collection of :class:`_schema.Column` objects.

        )r   r   primary_keyr8   s    r:   r   zFromClause.primary_key  s(     	 ((*r<   c                 Z    | j                          | j                          | j                  S )aV  Return the collection of :class:`_schema.ForeignKey` marker objects
        which this FromClause references.

        Each :class:`_schema.ForeignKey` is a member of a
        :class:`_schema.Table`-wide
        :class:`_schema.ForeignKeyConstraint`.

        .. seealso::

            :attr:`_schema.Table.foreign_key_constraints`

        )r   r   foreign_keysr8   s    r:   r   zFromClause.foreign_keys  s(     	 ((*   r<   c                 J    dD ]  }| j                   j                  |d         y)a  Reset the attributes linked to the ``FromClause.c`` attribute.

        This collection is separate from all the other memoized things
        as it has shown to be sensitive to being cleared out in situations
        where enclosing code, typically in a replacement traversal scenario,
        has already established strong relationships
        with the exported columns.

        The collection is cleared for the case where a table is having a
        column added to it as well as within a Join during copy internals.

        )r   r   r   r   N)r   r   )r9   keys     r:   _reset_column_collectionz#FromClause._reset_column_collection  s(     J 	)CMMc4(	)r<   r   a<  
        A named-based collection of :class:`_expression.ColumnElement`
        objects maintained by this :class:`_expression.FromClause`.

        The :attr:`_sql.FromClause.c` attribute is an alias for the
        :attr:`_sql.FromClause.columns` attribute.

        :return: a :class:`.ColumnCollection`

        )docc                     d| j                   vsJ d| j                   vsJ d| j                   vsJ t               | _        t               | _        t               | _        y )Nr   r   r   )r   r   r   r   r   setr   r8   s    r:   r   zFromClause._init_collections4  sV    ...DMM111T]]222(*$;Er<   c                     d| j                   v S )Nr   )r   r8   s    r:   _cols_populatedzFromClause._cols_populated=  s    T]]**r<   c                      y)zCalled on subclasses to establish the .c collection.

        Each implementation has a different way of establishing
        this collection.

        NrB   r8   s    r:   r   z&FromClause._populate_column_collectionA  s    r<   c                 $    | j                          y)aN  Given a column added to the .c collection of an underlying
        selectable, produce the local version of that column, assuming this
        selectable ultimately should proxy this column.

        this is used to "ping" a derived selectable to add a new column
        to its .c. collection when a Column has been added to one of the
        Table objects it ultimately derives from.

        If the given selectable hasn't populated its .c. collection yet,
        it should at least pass on the message to the contained selectables,
        but it will return None.

        This method is currently used by Declarative to allow Table
        columns to be added to a partially constructed inheritance
        mapping that may have already produced joins.  The method
        isn't public right now, as the full span of implications
        and/or caveats aren't yet clear.

        It's also possible that this functionality could be invoked by
        default via an event, which would require that
        selectables maintain a weak referencing collection of all
        derivations.

        N)r   r]   s     r:   r_   z"FromClause._refresh_for_new_columnI  s    2 	%%'r<   c                 &    | j                  |      S Nrf   )rH   r   s      r:   _anonymous_fromclausez FromClause._anonymous_fromclaused  s    zztz$$r<   r6   NFFNFNN))r=   r>   r?   rU   ru   named_with_column_hide_fromsschemarv   rW   _is_join_use_schema_mapr1   deprecated_paramsr   r   r   rH   rx   r   r   r   r   rA   r   r   rT   memoized_propertyr   r   r   r   r   r   r   _select_iterabler   r   r   r_   r   rB   r<   r:   r   r     s   ( "NKF MOHOT

$M%$M2,:\,7\,* T23< 4<6B 
.@ J J

  * 
, ,&   
    
! !")" 	9		A  
9 56" + +(6%r<   r   LABEL_STYLE_NONEav  Label style indicating no automatic labeling should be applied to the
    columns clause of a SELECT statement.

    Below, the columns named ``columna`` are both rendered as is, meaning that
    the name ``columna`` can only refer to the first occurrence of this name
    within a result set, as well as if the statement were used as a subquery::

        >>> from sqlalchemy import table, column, select, true, LABEL_STYLE_NONE
        >>> table1 = table("table1", column("columna"), column("columnb"))
        >>> table2 = table("table2", column("columna"), column("columnc"))
        >>> print(select(table1, table2).join(table2, true()).set_label_style(LABEL_STYLE_NONE))
        SELECT table1.columna, table1.columnb, table2.columna, table2.columnc
        FROM table1 JOIN table2 ON true

    Used with the :meth:`_sql.Select.set_label_style` method.

    .. versionadded:: 1.4

LABEL_STYLE_TABLENAME_PLUS_COLaM  Label style indicating all columns should be labeled as
    ``<tablename>_<columnname>`` when generating the columns clause of a SELECT
    statement, to disambiguate same-named columns referenced from different
    tables, aliases, or subqueries.

    Below, all column names are given a label so that the two same-named
    columns ``columna`` are disambiguated as ``table1_columna`` and
    ``table2_columna``::

        >>> from sqlalchemy import table, column, select, true, LABEL_STYLE_TABLENAME_PLUS_COL
        >>> table1 = table("table1", column("columna"), column("columnb"))
        >>> table2 = table("table2", column("columna"), column("columnc"))
        >>> print(select(table1, table2).join(table2, true()).set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL))
        SELECT table1.columna AS table1_columna, table1.columnb AS table1_columnb, table2.columna AS table2_columna, table2.columnc AS table2_columnc
        FROM table1 JOIN table2 ON true

    Used with the :meth:`_sql.GenerativeSelect.set_label_style` method.
    Equivalent to the legacy method ``Select.apply_labels()``;
    :data:`_sql.LABEL_STYLE_TABLENAME_PLUS_COL` is SQLAlchemy's legacy
    auto-labeling style. :data:`_sql.LABEL_STYLE_DISAMBIGUATE_ONLY` provides a
    less intrusive approach to disambiguation of same-named column expressions.


    .. versionadded:: 1.4

LABEL_STYLE_DISAMBIGUATE_ONLYa  Label style indicating that columns with a name that conflicts with
    an existing name should be labeled with a semi-anonymizing label
    when generating the columns clause of a SELECT statement.

    Below, most column names are left unaffected, except for the second
    occurrence of the name ``columna``, which is labeled using the
    label ``columna_1`` to disambiguate it from that of ``tablea.columna``::

        >>> from sqlalchemy import table, column, select, true, LABEL_STYLE_DISAMBIGUATE_ONLY
        >>> table1 = table("table1", column("columna"), column("columnb"))
        >>> table2 = table("table2", column("columna"), column("columnc"))
        >>> print(select(table1, table2).join(table2, true()).set_label_style(LABEL_STYLE_DISAMBIGUATE_ONLY))
        SELECT table1.columna, table1.columnb, table2.columna AS columna_1, table2.columnc
        FROM table1 JOIN table2 ON true

    Used with the :meth:`_sql.GenerativeSelect.set_label_style` method,
    :data:`_sql.LABEL_STYLE_DISAMBIGUATE_ONLY` is the default labeling style
    for all SELECT statements outside of :term:`1.x style` ORM queries.

    .. versionadded:: 1.4

c                       e Zd ZdZdZdej                  fdej                  fdej                  fdej                  fdej                  fgZdZ	d(d
Z
ed)d       Ze	 d(d       Zed        Zd Zd*dZ ej&                  d      d        Zef fd	Z fdZd Ze	 d+d       Zed*d       Ze ej&                  d      d               Zed        Z ej:                  dd      d*d       Ze ej>                  ddd	      d                Z  ej&                  d      d)d!       Z! ej>                  d"d#$      d)d%       Z"ed&        Z#ed'        Z$ xZ%S ),r   a  Represent a ``JOIN`` construct between two
    :class:`_expression.FromClause`
    elements.

    The public constructor function for :class:`_expression.Join`
    is the module-level
    :func:`_expression.join()` function, as well as the
    :meth:`_expression.FromClause.join` method
    of any :class:`_expression.FromClause` (e.g. such as
    :class:`_schema.Table`).

    .. seealso::

        :func:`_expression.join`

        :meth:`_expression.FromClause.join`

    r   leftr   r   r   r   TFc                    t        j                  t        j                  |d      | _        t        j                  t        j                  |d      j                         | _        |,| j                  | j                  | j                        | _        nGt        j                  t        j                  |      j                  t        j                        | _        || _        || _        y)zConstruct a new :class:`_expression.Join`.

        The usual entrypoint here is the :func:`_expression.join`
        function or the :meth:`_expression.FromClause.join` method of any
        :class:`_expression.FromClause` object.

        T)
deannotateNagainst)r   r   r   r   r  
self_groupr   _match_primariesr   OnClauseRoler   _asboolr   r   )r9   r  r   r   r   r   s         r:   __init__zJoin.__init__  s     $$  $4
	 %%  %D

*, 	
  11$))TZZHDM &,,""Hj!2!2j3 M 	r<   c                      | |||d|      S )a  Return an ``OUTER JOIN`` clause element.

        The returned object is an instance of :class:`_expression.Join`.

        Similar functionality is also available via the
        :meth:`_expression.FromClause.outerjoin` method on any
        :class:`_expression.FromClause`.

        :param left: The left side of the join.

        :param right: The right side of the join.

        :param onclause:  Optional criterion for the ``ON`` clause, is
          derived from foreign key relationships established between
          left and right otherwise.

        To chain joins together, use the :meth:`_expression.FromClause.join`
        or
        :meth:`_expression.FromClause.outerjoin` methods on the resulting
        :class:`_expression.Join` object.

        Tr   r   rB   )clsr  r   r   r   s        r:   _create_outerjoinzJoin._create_outerjoin  s    0 4$TBBr<   c                      | |||||      S )a6  Produce a :class:`_expression.Join` object, given two
        :class:`_expression.FromClause`
        expressions.

        E.g.::

            j = join(user_table, address_table,
                     user_table.c.id == address_table.c.user_id)
            stmt = select(user_table).select_from(j)

        would emit SQL along the lines of::

            SELECT user.id, user.name FROM user
            JOIN address ON user.id = address.user_id

        Similar functionality is available given any
        :class:`_expression.FromClause` object (e.g. such as a
        :class:`_schema.Table`) using
        the :meth:`_expression.FromClause.join` method.

        :param left: The left side of the join.

        :param right: the right side of the join; this is any
         :class:`_expression.FromClause` object such as a
         :class:`_schema.Table` object, and
         may also be a selectable-compatible object such as an ORM-mapped
         class.

        :param onclause: a SQL expression representing the ON clause of the
         join.  If left at ``None``, :meth:`_expression.FromClause.join`
         will attempt to
         join the two tables based on a foreign key relationship.

        :param isouter: if True, render a LEFT OUTER JOIN, instead of JOIN.

        :param full: if True, render a FULL OUTER JOIN, instead of JOIN.

         .. versionadded:: 1.1

        .. seealso::

            :meth:`_expression.FromClause.join` - method form,
            based on a given left side.

            :class:`_expression.Join` - the type of object produced.

        rB   )r  r  r   r   r   r   s         r:   _create_joinzJoin._create_join  s    h 4'488r<   c                     d| j                   j                  t        | j                         | j                  j                  t        | j                        fz  S )Nz Join object on %s(%d) and %s(%d))r  r   idr   r8   s    r:   r   zJoin.descriptionM  sD    1II!!tyyMJJ""tzzN	5
 
 	
r<   c                     t        |      t        |       k(  xs8 | j                  j                  |      xs | j                  j                  |      S r6   )hashr  r   r   r   s     r:   r   zJoin.is_derived_fromV  sH     T
* 6yy((46zz))*5	
r<   c                     t        |       S r6   )FromGroupingr9   r  s     r:   r  zJoin.self_group_  s    D!!r<   ri   c                 *   t         j                  j                  }| j                  j                  D cg c]  }| c}| j
                  j                  D cg c]  }| c}z   }| j                  j                  |j                  d |D        | j                               | j                  j                  d |D               | j                  j                  t        j                  |D cg c]  }|j                   c}        y c c}w c c}w c c}w )Nc              3   :   K   | ]  }|j                   s|  y wr6   )r   r   r   s     r:   r   z3Join._populate_column_collection.<locals>.<genexpr>k  s     5qq}}5s   c              3   8   K   | ]  }|j                   |f  y wr6   )_tq_key_label)r   r   s     r:   r   z3Join._populate_column_collection.<locals>.<genexpr>n  s       .
),S$.
   )r1   rk   rl   r  r   r   r   extendreduce_columnsr   r   r   r   update	itertoolschain)r9   sqlutilr   r   r   s        r:   r   z Join._populate_column_collectionb  s    ..))"ii//010zz))4
A4
 
 	""5G5t}}	

 	-- .
07.
 	
 	  OO'B3c..BC	
 1 4
 Cs   	D	D*Dc           	      *   t        t        j                  t        | j                        t        | j
                                    }|D ci c]  }| ||fi | c}fd}||d<   t        t        | "  dd|i| | j                          y c c}w )Nc                     t        | t              r/| j                  v r | j                     j                  |       }|S y y r6   
isinstancer(   tablerr   objr   newelem	new_fromss      r:   replacez%Join._copy_internals.<locals>.replace  ?    #|,i1G#CII.CCCH 2H,r<   r<  clonerB   )
r   r0  r1  r   r  r   superr   _copy_internals_reset_memoizations)r9   r>  r   all_the_fromsfr<  r;  r   s         @r:   r@  zJoin._copy_internalsu  s    
 OOdii(djj)
 1>>1Qa2&>	
	
  9
 	dD)<<<  "# ?s   Bc                     t         t        |   |       | j                  j                  |       | j                  j                  |       y r6   )r?  r   r_   r  r   r9   r^   r   s     r:   r_   zJoin._refresh_for_new_column  s6    dD1&9		))&1

**62r<   c                 h    t        |t              r|j                  }nd }| j                  |||      S )N)a_subset)r6  r   r   _join_condition)r9   r  r   
left_rights       r:   r  zJoin._match_primaries  s2    dD!JJ##D%*#EEr<   c                    | j                  ||||      }t        |      dkD  r| j                  ||||       t        |      dk(  rGt        |t              rd}nd}t        j                  d|j                  d|j                  d|      t        |j                               d   D cg c]
  \  }}||k(   }	}}t        |	      dk(  r|	d   S t        |	 S c c}}w )a=  Create a join condition between two tables or selectables.

        e.g.::

            join_condition(tablea, tableb)

        would produce an expression along the lines of::

            tablea.c.id==tableb.c.tablea_id

        The join is determined based on the foreign key relationships
        between the two selectables.   If there are multiple ways
        to join, or no way to join, an error is raised.

        :param a_subset: An optional expression that is a sub-component
         of ``a``.  An attempt will be made to join to just this sub-component
         first before looking at the full ``a`` construct, and if found
         will be successful even if there are other ways to join to ``a``.
         This allows the "right side" of a join to be passed thereby
         providing a "natural join".

        r   r   zI Perhaps you meant to convert the right side to a subquery using alias()? z2Can't find any foreign key relationships between '' and 'z'.)_joincond_scan_left_rightlen_joincond_trim_constraintsr6  r%  r0   NoForeignKeysErrorr   listvaluesr#   )
r  abrG  consider_as_foreign_keysconstraintshintxycrits
             r:   rH  zJoin._join_condition  s    4 33x4
 {a**1k#; {q !\*. 
 (( ==!--7  &*+*<*<*>%?%BCTQaCCt9>7N;	 Ds   +Cc                     t        |t              r|j                  }nd }| j                  ||||      }t	        |      S )N)rS  rT  rG  rU  )r6  r   r   rM  bool)r  r  r   rU  rI  rV  s         r:   	_can_joinzJoin._can_join  sH    dD!JJ33%=	 4 
 K  r<   c                 R   t         j                  j                  }t        j                  t
        j                  |      }t        j                  t
        j                  |      }t        j                  t              }||fD ]  }|t        |j                  d       D ]R  }||j                  |vr	 |j                  |      }	|	)||j&                     j)                  |	|j                  f       T ||urmt        |j                  d       D ]R  }||j                  |vr	 |j                  |      }	|	)||j&                     j)                  |	|j                  f       T |s |S  |S # t        j                  $ rH}
|j!                  |      D ch c]  }|j"                   nc c}w }}|
j$                  |v r Y d }
~
%d }
~
ww xY w# t        j                  $ rH}
|j!                  |      D ch c]  }|j"                   nc c}w }}|
j$                  |v r Y d }
~
d }
~
ww xY w)Nc                 .    | j                   j                  S r6   parent_creation_orderfks    r:   <lambda>z0Join._joincond_scan_left_right.<locals>.<lambda>  s    ryy/H/H r<   r   c                 .    | j                   j                  S r6   r`  rc  s    r:   re  z0Join._joincond_scan_left_right.<locals>.<lambda>  s    bii6O6O r<   )r1   rk   rl   r   r   r   r   collectionsdefaultdictrQ  sortedr   ra  get_referentr0   NoReferenceErrorfind_tablesrf   
table_name
constraintappend)r  rS  rG  rT  rU  rl   rV  r  rd  r   nrtettable_namess                r:   rM  zJoin._joincond_scan_left_right  s   
 >>**U1115U1115!--d3qM +	D|$H H -8		)AA!//$/C ?.55sBII6FG%H& 1} %%+O LB 1<II-EE % ooa0 #BMM2993		:JK%L& Y+	X ? ++ !3;3G3G3M"Na166"N"NK"N+5 !( // %7?7K7KA7N&O!qvv&O&O&O??k9!$%sH   3E-$G-G GF'
&GGH&H!1H
H!!H&c                    |r<t        |      D ].  }t        d |j                  D              t        |      k7  s,||= 0 t        |      dkD  rCt        d |j	                         D              }t        |      dk(  rt        |      d   }|||   i}t        |      dk7  r0t        j                  d|j                  d|j                  d      y )Nc              3   4   K   | ]  }|j                     y wr6   )ra  r   rC  s     r:   r   z2Join._joincond_trim_constraints.<locals>.<genexpr>,  s     8Aqxx8   r   c              3   2   K   | ]  }t        |        y wr6   )r   )r   rZ  s     r:   r   z2Join._joincond_trim_constraints.<locals>.<genexpr>4  s     FtFs   r   zCan't determine join between 'rL  z'; tables have more than one foreign key constraint relationship between them. Please specify the 'onclause' of this join explicitly.)rQ  r   elementsrN  rR  r0   AmbiguousForeignKeysErrorr   )r  rS  rT  rV  rU  constdeduper   s           r:   rO  zJoin._joincond_trim_constraints#  s     $k* +888C,=  $E*	+ {aF1C1C1EFFF6{a;'*"K$45{q //
 '(mmQ]]	D  !r<   )r   zThe :paramref:`_sql.Join.select().whereclause` parameter is deprecated and will be removed in version 2.0.  Please make use of the :meth:`.Select.where` method to add WHERE criteria to the SELECT statement.)r   zThe :meth:`_sql.Join.select` method will no longer accept keyword arguments in version 2.0.  Please use generative methods from the :class:`_sql.Select` construct in order to apply additional modifications.r   c                     | j                   | j                  g}|||d<   t        j                  | |fi |j	                  |       S )a  Create a :class:`_expression.Select` from this
        :class:`_expression.Join`.

        E.g.::

            stmt = table_a.join(table_b, table_a.c.id == table_b.c.a_id)

            stmt = stmt.select()

        The above will produce a SQL string resembling::

            SELECT table_a.id, table_a.col, table_b.id, table_b.a_id
            FROM table_a JOIN table_b ON table_a.id = table_b.a_id

        :param whereclause: WHERE criteria, same as calling
          :meth:`_sql.Select.where` on the resulting statement

        :param \**kwargs: additional keyword arguments are passed to the
         legacy constructor for :class:`_sql.Select` described at
         :meth:`_sql.Select.create_legacy_select`.

        r   )r  r   rE   r   select_from)r9   r   rJ   collists       r:   r   zJoin.selectB  sQ    R 99djj)"$/F=!44'
#

+d
	r<   :attr:`.Executable.bind`5Bound metadata is being removed as of SQLAlchemy 2.0.alternativeenable_warningsc                 ^    | j                   j                  xs | j                  j                  S )zsReturn the bound engine associated with either the left or right
        side of this :class:`_sql.Join`.

        )r  bindr   r8   s    r:   r  z	Join.binds  s     yy~~00r<   c                 <   t         j                  j                  }|r|t        j                  d      | j
                  j                  d      | j                  j                  d      }}|j                  |      j                  |j                  |            }|j                  ||j                  | j                        | j                  | j                        S | j                         j!                  t"              j%                  d       j'                  |      S )Nz"Can't send name argument with flatT)r   r  )r1   rk   rl   r0   r   r  r   r   rm   r1  r   rn   r   r   r   r   set_label_styler  	correlaterH   )r9   rf   r   r2  left_aright_aadapters          r:   r   zJoin._anonymous_fromclause  s    ..))''(LMM		//T/:

00d0; F ++F399%%g.G ;;  /YY	     !?@4t	r<   z:meth:`_sql.Join.alias`zTCreate a select + subquery, or alias the individual tables inside the join, instead.r  c                 (    | j                  ||      S )a@  Return an alias of this :class:`_expression.Join`.

        The default behavior here is to first produce a SELECT
        construct from this :class:`_expression.Join`, then to produce an
        :class:`_expression.Alias` from that.  So given a join of the form::

            j = table_a.join(table_b, table_a.c.id == table_b.c.a_id)

        The JOIN by itself would look like::

            table_a JOIN table_b ON table_a.id = table_b.a_id

        Whereas the alias of the above, ``j.alias()``, would in a
        SELECT context look like::

            (SELECT table_a.id AS table_a_id, table_b.id AS table_b_id,
                table_b.a_id AS table_b_a_id
                FROM table_a
                JOIN table_b ON table_a.id = table_b.a_id) AS anon_1

        The equivalent long-hand form, given a :class:`_expression.Join`
        object ``j``, is::

            from sqlalchemy import select, alias
            j = alias(
                select(j.left, j.right).\
                    select_from(j).\
                    set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL).\
                    correlate(False),
                name=name
            )

        The selectable produced by :meth:`_expression.Join.alias`
        features the same
        columns as that of the two individual selectables presented under
        a single name - the individual columns are "auto-labeled", meaning
        the ``.c.`` collection of the resulting :class:`_expression.Alias`
        represents
        the names of the individual columns using a
        ``<tablename>_<columname>`` scheme::

            j.c.table_a_id
            j.c.table_b_a_id

        :meth:`_expression.Join.alias` also features an alternate
        option for aliasing joins which produces no enclosing SELECT and
        does not normally apply labels to the column names.  The
        ``flat=True`` option will call :meth:`_expression.FromClause.alias`
        against the left and right sides individually.
        Using this option, no new ``SELECT`` is produced;
        we instead, from a construct as below::

            j = table_a.join(table_b, table_a.c.id == table_b.c.a_id)
            j = j.alias(flat=True)

        we get a result like this::

            table_a AS table_a_1 JOIN table_b AS table_b_1 ON
            table_a_1.id = table_b_1.a_id

        The ``flat=True`` argument is also propagated to the contained
        selectables, so that a composite join such as::

            j = table_a.join(
                    table_b.join(table_c,
                            table_b.c.id == table_c.c.b_id),
                    table_b.c.a_id == table_a.c.id
                ).alias(flat=True)

        Will produce an expression like::

            table_a AS table_a_1 JOIN (
                    table_b AS table_b_1 JOIN table_c AS table_c_1
                    ON table_b_1.id = table_c_1.b_id
            ) ON table_a_1.id = table_b_1.a_id

        The standalone :func:`_expression.alias` function as well as the
        base :meth:`_expression.FromClause.alias`
        method also support the ``flat=True``
        argument as a no-op, so that the argument can be passed to the
        ``alias()`` method of any selectable.

        :param name: name given to the alias.

        :param flat: if True, produce an alias of the left and right
         sides of this :class:`_expression.Join` and return the join of those
         two selectables.   This produces join expression that does not
         include an enclosing SELECT.

        .. seealso::

            :ref:`core_tutorial_aliases`

            :func:`_expression.alias`

        )r   rf   )r   r   s      r:   rH   z
Join.alias  s    L ))t$)??r<   c           	          t        j                  | j                  D cg c]"  }t        |j                  |j
                        $ c} S c c}w r6   )r0  r1  r   r   r  r   )r9   rX  s     r:   r  zJoin._hide_froms  s9    6:6F6FGmAFFAGG,G
 	
Gs   'A	c                 d    | g| j                   j                  z   | j                  j                  z   S r6   )r  r   r   r8   s    r:   r   zJoin._from_objects  s(    v		///$**2J2JJJr<   r  r  r6   r  )&r=   r>   r?   rU   ru   r.   dp_clauseelement
dp_boolean_traverse_internalsr  r  classmethodr  r  rA   r   r   r  r1   rx   r   r   r@  r_   r  rH  r]  rM  rO  r	  r   deprecated_20r  r   rH   r  r   __classcell__r   s   @r:   r   r     s6   & N 
"334	#445	&778	%001	"--. H6 C C2 =B39 39j 
 

" T./
 0
$ %+ #B3
F ;?4 4l ! ! T./6 0 6p  < T

$%$> T"K
1 1 T./ 06 T!6
a@
a@F 
 

 K Kr<   r   c                       e Zd Zd Zy)NoInitc           	          t        d| j                  j                  d| j                  j                  j                         d| j                  j                  j                         d      )NzThe zC class is not intended to be constructed directly.  Please use the z() standalone function or the z8() method available from appropriate selectable objects.)rQ   r   r=   lowerr9   argr   s      r:   r  zNoInit.__init__  sO    ! ''''--/''--/

 
	
r<   Nr=   r>   r?   r  rB   r<   r:   r  r    s    
r<   r  c                        e Zd ZdZdZdZdZdej                  fdej                  fgZ
ed        Zedd       ZddZ fd	Zed
        Zed        Zd Zd Zef fd	Zed        Zed        Z xZS )AliasedReturnsRowszLBase class of aliases against tables, subqueries, and other
    selectables.TFelementrf   c                 L    | j                  |       } |j                  |i | |S r6   )__new___init)r  r  r   r9  s       r:   rd   zAliasedReturnsRows._construct5  s(    kk#		3"
r<   c                     t               )z6Base factory method.  Subclasses need to provide this.rP   )r  returnsrowsrf   s      r:   _factoryzAliasedReturnsRows._factory;  s     "##r<   c                 D   t        j                  t        j                  ||       | _        || _        || _        |^t        |t              r+|j                  rt        |dd       }t        |t              rd }t        j                  t        |       |xs d      }|| _        y )Napply_propagate_attrsrf   anon)r   r   r   ReturnsRowsRoler  
_orig_namer6  r   r  r   r"   safe_constructr!  rf   )r9   rN   rf   s      r:   r  zAliasedReturnsRows._init@  s     ''!!:T
 "<:z200z648d$45D#222d8T^VLD	r<   c                 b    t         t        |   |       | j                  j                  |       y r6   )r?  r  r_   r  rE  s     r:   r_   z*AliasedReturnsRows._refresh_for_new_columnQ  s%     $?G,,V4r<   c                     | j                   }t        |t              rd}t        j                  r|S |j                  dd      S )Nanon_1asciibackslashreplace)rf   r6  r"   r1   py3kencodere   s     r:   r   zAliasedReturnsRows.descriptionU  s9    yyd,-D99K;;w(:;;r<   c                     | j                   S )z9Legacy for dialects that are referring to Alias.original.r  r8   s    r:   originalzAliasedReturnsRows.original`  s     ||r<   c                 V    || j                   v ry| j                  j                  |      S NT)r   r  r   r   s     r:   r   z"AliasedReturnsRows.is_derived_frome  s(    )))||++J77r<   c                 :    | j                   j                  |        y r6   r  r   r8   s    r:   r   z.AliasedReturnsRows._populate_column_collectionj  s    88>r<   c                     | j                   }t        t        |   dd|i| || j                   ur| j	                          y y )Nr>  rB   )r  r?  r  r@  r   )r9   r>  r   existing_elementr   s       r:   r@  z"AliasedReturnsRows._copy_internalsm  sD    << $7JeJrJ 4<</))+ 0r<   c                     | gS r6   rB   r8   s    r:   r   z AliasedReturnsRows._from_objectsy  	    vr<   c                 .    | j                   j                  S r6   )r  r  r8   s    r:   r  zAliasedReturnsRows.bind}  s    ||   r<   r6   )r=   r>   r?   rU   _is_from_containerr  _supports_derived_columnsr.   r  dp_anon_namer  r  rd   r  r  r_   rA   r   r  r   r   r   r@  r   r  r  r  s   @r:   r  r  '  s      % 
%667	"//0
  
 $ $"5 < <  8
? %+ 
,   ! !r<   r  c                   *    e Zd ZdZdZdZedd       Zy)r   a  Represents an table or selectable alias (AS).

    Represents an alias, as typically applied to any table or
    sub-select within a SQL statement using the ``AS`` keyword (or
    without the keyword on certain databases such as Oracle).

    This object is constructed from the :func:`_expression.alias` module
    level function as well as the :meth:`_expression.FromClause.alias`
    method available
    on all :class:`_expression.FromClause` subclasses.

    .. seealso::

        :meth:`_expression.FromClause.alias`

    rH   TNc                 p    t        j                  t        j                  |d      j	                  ||      S )a  Return an :class:`_expression.Alias` object.

        An :class:`_expression.Alias` represents any
        :class:`_expression.FromClause`
        with an alternate name assigned within SQL, typically using the ``AS``
        clause when generated, e.g. ``SELECT * FROM table AS aliasname``.

        Similar functionality is available via the
        :meth:`_expression.FromClause.alias`
        method available on all :class:`_expression.FromClause` subclasses.
        In terms of
        a SELECT object as generated from the :func:`_expression.select`
        function, the :meth:`_expression.SelectBase.alias` method returns an
        :class:`_expression.Alias` or similar object which represents a named,
        parenthesized subquery.

        When an :class:`_expression.Alias` is created from a
        :class:`_schema.Table` object,
        this has the effect of the table being rendered
        as ``tablename AS aliasname`` in a SELECT statement.

        For :func:`_expression.select` objects, the effect is that of
        creating a named subquery, i.e. ``(select ...) AS aliasname``.

        The ``name`` parameter is optional, and provides the name
        to use in the rendered SQL.  If blank, an "anonymous" name
        will be deterministically generated at compile time.
        Deterministic means the name is guaranteed to be unique against
        other constructs used in the same statement, and will also be the
        same name for each successive compilation of the same statement
        object.

        :param selectable: any :class:`_expression.FromClause` subclass,
            such as a table, select statement, etc.

        :param name: string name to be assigned as the alias.
            If ``None``, a name will be deterministically generated
            at compile time.

        :param flat: Will be passed through to if the given selectable
         is an instance of :class:`_expression.Join` - see
         :meth:`_expression.Join.alias`
         for details.

        T)allow_select)rf   r   )r   r   r   r   rH   )r  rN   rf   r   s       r:   r  zAlias._factory  s3    ^   *4

%T%
%	&r<   r  )r=   r>   r?   rU   ru   r@   r  r  rB   r<   r:   r   r     s%    " NM0& 0&r<   r   c                        e Zd ZdZdZdZdZdZdZde	j                  fde	j                  fde	j                  fde	j                  fd	e	j                  fgZ	 	 	 d fd
	Zej"                  d        ZddZddZddZ xZS )TableValuedAliasa  An alias against a "table valued" SQL function.

    This construct provides for a SQL function that returns columns
    to be used in the FROM clause of a SELECT statement.   The
    object is generated using the :meth:`_functions.FunctionElement.table_valued`
    method, e.g.::

        >>> from sqlalchemy import select, func
        >>> fn = func.json_array_elements_text('["one", "two", "three"]').table_valued("value")
        >>> print(select(fn.c.value))
        SELECT anon_1.value
        FROM json_array_elements_text(:json_array_elements_text_1) AS anon_1

    .. versionadded:: 1.4.0b2

    .. seealso::

        :ref:`tutorial_functions_table_valued` - in the :ref:`unified_tutorial`

    table_valued_aliasTFr  rf   _tableval_type_render_derived_render_derived_w_typesc                 |    t         t        |   ||       || _        |t        j
                  | _        y || _        y r   )r?  r  r  joins_implicitlyr	   r   r  )r9   rN   rf   table_value_typer  r   s        r:   r  zTableValuedAlias._init  sJ     	+JT+B 0  '  	 " 	r<   c                 .    t        | | j                        S )a  Return a column expression representing this
        :class:`_sql.TableValuedAlias`.

        This accessor is used to implement the
        :meth:`_functions.FunctionElement.column_valued` method. See that
        method for further details.

        E.g.::

            >>> print(select(func.some_func().table_valued("value").column))
            SELECT anon_1 FROM some_func() AS anon_1

        .. seealso::

            :meth:`_functions.FunctionElement.column_valued`

        )r,   r  r8   s    r:   r^   zTableValuedAlias.column  s    ( !t':':;;r<   c                     t         j                  | || j                  | j                        }| j                  rd|_        | j
                  |_        |S )zReturn a new alias of this :class:`_sql.TableValuedAlias`.

        This creates a distinct FROM object that will be distinguished
        from the original one when used in a SQL statement.

        rf   r  r  T)r  rd   r  r  r  r  r9   rf   tvas      r:   rH   zTableValuedAlias.alias  sW     ))!00!22	 * 
 "&C*.*F*FC'
r<   c                 8    | j                  |      }d|_        |S )zReturn a new :class:`_sql.TableValuedAlias` with the lateral flag
        set, so that it renders as LATERAL.

        .. seealso::

            :func:`_expression.lateral`

        r   T)rH   rY   r  s      r:   rg   zTableValuedAlias.lateral,  s      jjdj#
r<   c                     t         j                  | j                  || j                  | j                        }d|_        ||_        |S )af  Apply "render derived" to this :class:`_sql.TableValuedAlias`.

        This has the effect of the individual column names listed out
        after the alias name in the "AS" sequence, e.g.::

            >>> print(
            ...     select(
            ...         func.unnest(array(["one", "two", "three"])).
                        table_valued("x", with_ordinality="o").render_derived()
            ...     )
            ... )
            SELECT anon_1.x, anon_1.o
            FROM unnest(ARRAY[%(param_1)s, %(param_2)s, %(param_3)s]) WITH ORDINALITY AS anon_1(x, o)

        The ``with_types`` keyword will render column types inline within
        the alias expression (this syntax currently applies to the
        PostgreSQL database)::

            >>> print(
            ...     select(
            ...         func.json_to_recordset(
            ...             '[{"a":1,"b":"foo"},{"a":"2","c":"bar"}]'
            ...         )
            ...         .table_valued(column("a", Integer), column("b", String))
            ...         .render_derived(with_types=True)
            ...     )
            ... )
            SELECT anon_1.a, anon_1.b FROM json_to_recordset(:json_to_recordset_1)
            AS anon_1(a INTEGER, b VARCHAR)

        :param name: optional string name that will be applied to the alias
         generated.  If left as None, a unique anonymizing name will be used.

        :param with_types: if True, the derived columns will include the
         datatype specification with each column. This is a special syntax
         currently known to be required by PostgreSQL for some SQL functions.

        r  T)r  rd   r  r  r  r  r  )r9   rf   
with_types	new_aliass       r:   render_derivedzTableValuedAlias.render_derived9  sN    ` %//LL!00!22	 0 
	 %)	!,6	)r<   NNFr6   r  )r=   r>   r?   rU   ru   r  r  r  r  r.   r  r  dp_typer  r  r  r   memoized_attributer^   rH   rg   r  r  r  s   @r:   r  r    s    * *N $O# 
%667	"//0	,445	-889	"$5$@$@A 
  ##< $<**8r<   r  c                   .    e Zd ZdZdZdZdZedd       Zy)rc   a  Represent a LATERAL subquery.

    This object is constructed from the :func:`_expression.lateral` module
    level function as well as the :meth:`_expression.FromClause.lateral`
    method available
    on all :class:`_expression.FromClause` subclasses.

    While LATERAL is part of the SQL standard, currently only more recent
    PostgreSQL versions provide support for this keyword.

    .. versionadded:: 1.1

    .. seealso::

        :ref:`tutorial_lateral_correlation` -  overview of usage.

    rg   TNc                 n    t        j                  t        j                  |d      j	                  |      S )a  Return a :class:`_expression.Lateral` object.

        :class:`_expression.Lateral` is an :class:`_expression.Alias`
        subclass that represents
        a subquery with the LATERAL keyword applied to it.

        The special behavior of a LATERAL subquery is that it appears in the
        FROM clause of an enclosing SELECT, but may correlate to other
        FROM clauses of that SELECT.   It is a special case of subquery
        only supported by a small number of backends, currently more recent
        PostgreSQL versions.

        .. versionadded:: 1.1

        .. seealso::

            :ref:`tutorial_lateral_correlation` -  overview of usage.


        T)explicit_subqueryr   )r   r   r   r   rg   r  rN   rf   s      r:   r  zLateral._factory  s0    ,   *

't'
	r<   r6   )	r=   r>   r?   rU   ru   rY   r@   r  r  rB   r<   r:   rc   rc   t  s*    $ NKM r<   rc   c                        e Zd ZdZdZej                  dej                  fdej                  fgz   Ze	d	d       Z
 ej                  d      d	 fd	       Zd Z xZS )
r   ad  Represent a TABLESAMPLE clause.

    This object is constructed from the :func:`_expression.tablesample` module
    level function as well as the :meth:`_expression.FromClause.tablesample`
    method
    available on all :class:`_expression.FromClause` subclasses.

    .. versionadded:: 1.1

    .. seealso::

        :func:`_expression.tablesample`

    r   r   r   c                 n    t        j                  t        j                  |      j	                  |||      S )a  Return a :class:`_expression.TableSample` object.

        :class:`_expression.TableSample` is an :class:`_expression.Alias`
        subclass that represents
        a table with the TABLESAMPLE clause applied to it.
        :func:`_expression.tablesample`
        is also available from the :class:`_expression.FromClause`
        class via the
        :meth:`_expression.FromClause.tablesample` method.

        The TABLESAMPLE clause allows selecting a randomly selected approximate
        percentage of rows from a table. It supports multiple sampling methods,
        most commonly BERNOULLI and SYSTEM.

        e.g.::

            from sqlalchemy import func

            selectable = people.tablesample(
                        func.bernoulli(1),
                        name='alias',
                        seed=func.random())
            stmt = select(selectable.c.people_id)

        Assuming ``people`` with a column ``people_id``, the above
        statement would render as::

            SELECT alias.people_id FROM
            people AS alias TABLESAMPLE bernoulli(:bernoulli_1)
            REPEATABLE (random())

        .. versionadded:: 1.1

        :param sampling: a ``float`` percentage between 0 and 100 or
            :class:`_functions.Function`.

        :param name: optional alias name

        :param seed: any real-valued SQL expression.  When specified, the
         REPEATABLE sub-clause is also rendered.

        )rf   r   )r   r   r   r   r   )r  rN   r   rf   r   s        r:   r  zTableSample._factory  s8    X  4 4jAMM4d N 
 	
r<   zsqlalchemy.sql.functionsc                     t         j                  j                  }t        ||j                        s|j
                  j                  |      }|| _        || _        t        t        | /  ||       y r   )r1   rk   sql_functionsr6  Functionfuncsystemr   r   r?  r   r  )r9   rN   r   rf   r   	functionsr   s         r:   r  zTableSample._init  sX    NN00	(I$6$67 ~~,,X6H 	k4&z&=r<   c                     | j                   S r6   )r   r8   s    r:   _get_methodzTableSample._get_method  s    }}r<   r  )r=   r>   r?   rU   ru   r  r  r.   r  r  r  r1   rx   r  r  r  r  s   @r:   r   r     s     #N,@@	&778	"334D 
 -
 -
^ T34> 5>r<   r   c                   "    e Zd ZdZdZej                  dej                  fdej                  fdej                  fdej                  fgz   e
j                  z   ej                  z   Zedd       Z	 	 	 	 	 	 	 d fd	Zd	 Zdd
Zd Zd Zd Z xZS )CTEaU  Represent a Common Table Expression.

    The :class:`_expression.CTE` object is obtained using the
    :meth:`_sql.SelectBase.cte` method from any SELECT statement. A less often
    available syntax also allows use of the :meth:`_sql.HasCTE.cte` method
    present on :term:`DML` constructs such as :class:`_sql.Insert`,
    :class:`_sql.Update` and
    :class:`_sql.Delete`.   See the :meth:`_sql.HasCTE.cte` method for
    usage details on CTEs.

    .. seealso::

        :ref:`tutorial_subqueries_ctes` - in the 2.0 tutorial

        :meth:`_sql.HasCTE.cte` - examples of calling styles

    cte
_cte_alias	_restates	recursivenestingc                 l    t        j                  t        j                  |      j	                  ||      S )zReturn a new :class:`_expression.CTE`,
        or Common Table Expression instance.

        Please see :meth:`_expression.HasCTE.cte` for detail on CTE usage.

        )rf   r  )r   r   r   
HasCTERoler  )r  rN   rf   r  s       r:   r  zCTE._factory$  s5      0 0*=AA B 
 	
r<   c	                     || _         || _        || _        || _        |r|| _        |r|| _        t        t        | #  ||       y r   )	r  r  r  r  r{   r   r?  r  r  )
r9   rN   rf   r  r  r  r  r{   r   r   s
            r:   r  z	CTE._init0  sI     #$"&DN&DNc4z5r<   c                     | j                   | j                   j                  |        y | j                  j                  |        y r6   )r  r   r  r8   s    r:   r   zCTE._populate_column_collectionF  s0    ??&OO??ELL<<TBr<   c           	          t         j                  | j                  || j                  | j                  | | j
                  | j                        S )a2  Return an :class:`_expression.Alias` of this
        :class:`_expression.CTE`.

        This method is a CTE-specific specialization of the
        :meth:`_expression.FromClause.alias` method.

        .. seealso::

            :ref:`tutorial_using_aliases`

            :func:`_expression.alias`

        )rf   r  r  r  r{   r   )r  rd   r  r  r  r{   r   r   s      r:   rH   z	CTE.aliasL  sC     ~~LLnnLLnnnn  
 	
r<   c           	          t         j                   | j                  j                  | | j                  | j
                  | j                  | | j                  | j                        S )a  Return a new :class:`_expression.CTE` with a SQL ``UNION``
        of the original CTE against the given selectables provided
        as positional arguments.

        :param \*other: one or more elements with which to create a
         UNION.

         .. versionchanged:: 1.4.28 multiple elements are now accepted.

        .. seealso::

            :meth:`_sql.HasCTE.cte` - examples of calling styles

        rf   r  r  r  r{   r   )	r  rd   r  r   rf   r  r  r{   r   r   s     r:   r   z	CTE.uniond  sT     ~~DLL&nnLLnnnn  
 	
r<   c           	          t         j                   | j                  j                  | | j                  | j
                  | j                  | | j                  | j                        S )a  Return a new :class:`_expression.CTE` with a SQL ``UNION ALL``
        of the original CTE against the given selectables provided
        as positional arguments.

        :param \*other: one or more elements with which to create a
         UNION.

         .. versionchanged:: 1.4.28 multiple elements are now accepted.

        .. seealso::

            :meth:`_sql.HasCTE.cte` - examples of calling styles

        r  )	r  rd   r  	union_allrf   r  r  r{   r   r   s     r:   r  zCTE.union_all}  sT     ~~"DLL""E*nnLLnnnn  
 	
r<   c                 6    | j                   | j                   S | S )z
        A recursive CTE is updated to attach the recursive part.
        Updated CTEs should still refer to the original CTE.
        This function returns this reference identifier.
        )r  r8   s    r:   _get_reference_ctezCTE._get_reference_cte  s     "&!;t~~EEr<   r  )NFFNNNN)r=   r>   r?   rU   ru   r  r  r.   r  r  rz   r   r   r   r  r  r  r   rH   r   r  r  r  r  s   @r:   r  r    s    $ N 	..,==>+<<=+667)445	
	
 
6
6	7 
6
6	7  	
 	
 6,C
0
2
2Fr<   r  c                   J    e Zd ZdZdej
                  fgZdZed        Z	ddZ
y)HasCTEzTMixin that declares a class to include CTE support.

    .. versionadded:: 1.1

    _independent_ctesrB   c                 x    t        j                  t        j                  |      }| xj                  |fz  c_        y)ad  Add a :class:`_sql.CTE` to this statement object that will be
        independently rendered even if not referenced in the statement
        otherwise.

        This feature is useful for the use case of embedding a DML statement
        such as an INSERT or UPDATE as a CTE inline with a primary statement
        that may draw from its results indirectly; while PostgreSQL is known
        to support this usage, it may not be supported by other backends.

        E.g.::

            from sqlalchemy import table, column, select
            t = table('t', column('c1'), column('c2'))

            ins = t.insert().values({"c1": "x", "c2": "y"}).cte()

            stmt = select(t).add_cte(ins)

        Would render::

            WITH anon_1 AS
            (INSERT INTO t (c1, c2) VALUES (:param_1, :param_2))
            SELECT t.c1, t.c2
            FROM t

        Above, the "anon_1" CTE is not referred towards in the SELECT
        statement, however still accomplishes the task of running an INSERT
        statement.

        Similarly in a DML-related context, using the PostgreSQL
        :class:`_postgresql.Insert` construct to generate an "upsert"::

            from sqlalchemy import table, column
            from sqlalchemy.dialects.postgresql import insert

            t = table("t", column("c1"), column("c2"))

            delete_statement_cte = (
                t.delete().where(t.c.c1 < 1).cte("deletions")
            )

            insert_stmt = insert(t).values({"c1": 1, "c2": 2})
            update_statement = insert_stmt.on_conflict_do_update(
                index_elements=[t.c.c1],
                set_={
                    "c1": insert_stmt.excluded.c1,
                    "c2": insert_stmt.excluded.c2,
                },
            ).add_cte(delete_statement_cte)

            print(update_statement)

        The above statement renders as::

            WITH deletions AS
            (DELETE FROM t WHERE t.c1 < %(c1_1)s)
            INSERT INTO t (c1, c2) VALUES (%(c1)s, %(c2)s)
            ON CONFLICT (c1) DO UPDATE SET c1 = excluded.c1, c2 = excluded.c2

        .. versionadded:: 1.4.21

        N)r   r   r   	IsCTERoler   )r9   r  s     r:   add_ctezHasCTE.add_cte  s.    @ u43&(r<   Nc                 4    t         j                  | |||      S )aK"  Return a new :class:`_expression.CTE`,
        or Common Table Expression instance.

        Common table expressions are a SQL standard whereby SELECT
        statements can draw upon secondary statements specified along
        with the primary statement, using a clause called "WITH".
        Special semantics regarding UNION can also be employed to
        allow "recursive" queries, where a SELECT statement can draw
        upon the set of rows that have previously been selected.

        CTEs can also be applied to DML constructs UPDATE, INSERT
        and DELETE on some databases, both as a source of CTE rows
        when combined with RETURNING, as well as a consumer of
        CTE rows.

        .. versionchanged:: 1.1 Added support for UPDATE/INSERT/DELETE as
           CTE, CTEs added to UPDATE/INSERT/DELETE.

        SQLAlchemy detects :class:`_expression.CTE` objects, which are treated
        similarly to :class:`_expression.Alias` objects, as special elements
        to be delivered to the FROM clause of the statement as well
        as to a WITH clause at the top of the statement.

        For special prefixes such as PostgreSQL "MATERIALIZED" and
        "NOT MATERIALIZED", the :meth:`_expression.CTE.prefix_with`
        method may be
        used to establish these.

        .. versionchanged:: 1.3.13 Added support for prefixes.
           In particular - MATERIALIZED and NOT MATERIALIZED.

        :param name: name given to the common table expression.  Like
         :meth:`_expression.FromClause.alias`, the name can be left as
         ``None`` in which case an anonymous symbol will be used at query
         compile time.
        :param recursive: if ``True``, will render ``WITH RECURSIVE``.
         A recursive common table expression is intended to be used in
         conjunction with UNION ALL in order to derive rows
         from those already selected.
        :param nesting: if ``True``, will render the CTE locally to the
         actual statement.

         .. versionadded:: 1.4.24

        The following examples include two from PostgreSQL's documentation at
        https://www.postgresql.org/docs/current/static/queries-with.html,
        as well as additional examples.

        Example 1, non recursive::

            from sqlalchemy import (Table, Column, String, Integer,
                                    MetaData, select, func)

            metadata = MetaData()

            orders = Table('orders', metadata,
                Column('region', String),
                Column('amount', Integer),
                Column('product', String),
                Column('quantity', Integer)
            )

            regional_sales = select(
                                orders.c.region,
                                func.sum(orders.c.amount).label('total_sales')
                            ).group_by(orders.c.region).cte("regional_sales")


            top_regions = select(regional_sales.c.region).\
                    where(
                        regional_sales.c.total_sales >
                        select(
                            func.sum(regional_sales.c.total_sales) / 10
                        )
                    ).cte("top_regions")

            statement = select(
                        orders.c.region,
                        orders.c.product,
                        func.sum(orders.c.quantity).label("product_units"),
                        func.sum(orders.c.amount).label("product_sales")
                ).where(orders.c.region.in_(
                    select(top_regions.c.region)
                )).group_by(orders.c.region, orders.c.product)

            result = conn.execute(statement).fetchall()

        Example 2, WITH RECURSIVE::

            from sqlalchemy import (Table, Column, String, Integer,
                                    MetaData, select, func)

            metadata = MetaData()

            parts = Table('parts', metadata,
                Column('part', String),
                Column('sub_part', String),
                Column('quantity', Integer),
            )

            included_parts = select(\
                parts.c.sub_part, parts.c.part, parts.c.quantity\
                ).\
                where(parts.c.part=='our part').\
                cte(recursive=True)


            incl_alias = included_parts.alias()
            parts_alias = parts.alias()
            included_parts = included_parts.union_all(
                select(
                    parts_alias.c.sub_part,
                    parts_alias.c.part,
                    parts_alias.c.quantity
                ).\
                where(parts_alias.c.part==incl_alias.c.sub_part)
            )

            statement = select(
                        included_parts.c.sub_part,
                        func.sum(included_parts.c.quantity).
                          label('total_quantity')
                    ).\
                    group_by(included_parts.c.sub_part)

            result = conn.execute(statement).fetchall()

        Example 3, an upsert using UPDATE and INSERT with CTEs::

            from datetime import date
            from sqlalchemy import (MetaData, Table, Column, Integer,
                                    Date, select, literal, and_, exists)

            metadata = MetaData()

            visitors = Table('visitors', metadata,
                Column('product_id', Integer, primary_key=True),
                Column('date', Date, primary_key=True),
                Column('count', Integer),
            )

            # add 5 visitors for the product_id == 1
            product_id = 1
            day = date.today()
            count = 5

            update_cte = (
                visitors.update()
                .where(and_(visitors.c.product_id == product_id,
                            visitors.c.date == day))
                .values(count=visitors.c.count + count)
                .returning(literal(1))
                .cte('update_cte')
            )

            upsert = visitors.insert().from_select(
                [visitors.c.product_id, visitors.c.date, visitors.c.count],
                select(literal(product_id), literal(day), literal(count))
                    .where(~exists(update_cte.select()))
            )

            connection.execute(upsert)

        Example 4, Nesting CTE (SQLAlchemy 1.4.24 and above)::

            value_a = select(
                literal("root").label("n")
            ).cte("value_a")

            # A nested CTE with the same name as the root one
            value_a_nested = select(
                literal("nesting").label("n")
            ).cte("value_a", nesting=True)

            # Nesting CTEs takes ascendency locally
            # over the CTEs at a higher level
            value_b = select(value_a_nested.c.n).cte("value_b")

            value_ab = select(value_a.c.n.label("a"), value_b.c.n.label("b"))

        The above query will render the second CTE nested inside the first,
        shown with inline parameters below as::

            WITH
                value_a AS
                    (SELECT 'root' AS n),
                value_b AS
                    (WITH value_a AS
                        (SELECT 'nesting' AS n)
                    SELECT value_a.n AS n FROM value_a)
            SELECT value_a.n AS a, value_b.n AS b
            FROM value_a, value_b

        Example 5, Non-Linear CTE (SQLAlchemy 1.4.28 and above)::

            edge = Table(
                "edge",
                metadata,
                Column("id", Integer, primary_key=True),
                Column("left", Integer),
                Column("right", Integer),
            )

            root_node = select(literal(1).label("node")).cte(
                "nodes", recursive=True
            )

            left_edge = select(edge.c.left).join(
                root_node, edge.c.right == root_node.c.node
            )
            right_edge = select(edge.c.right).join(
                root_node, edge.c.left == root_node.c.node
            )

            subgraph_cte = root_node.union(left_edge, right_edge)

            subgraph = select(subgraph_cte)

        The above query will render 2 UNIONs inside the recursive CTE::

            WITH RECURSIVE nodes(node) AS (
                    SELECT 1 AS node
                UNION
                    SELECT edge."left" AS "left"
                    FROM edge JOIN nodes ON edge."right" = nodes.node
                UNION
                    SELECT edge."right" AS "right"
                    FROM edge JOIN nodes ON edge."left" = nodes.node
            )
            SELECT nodes.node FROM nodes

        .. seealso::

            :meth:`_orm.Query.cte` - ORM version of
            :meth:`_expression.HasCTE.cte`.

        )rf   r  r  )r  rd   )r9   rf   r  r  s       r:   r  z
HasCTE.cte  s$    \ ~~ty'  
 	
r<   r  )r=   r>   r?   rU   r.   dp_clauseelement_list_has_ctes_traverse_internalsr   r   r  r  rB   r<   r:   r  r    sC     
/EEF$  @) @)Dp
r<   r  c                   f    e Zd ZdZdZdZdZed
d       Z e	j                  dd      d        Zd	 Zy)Subquerya  Represent a subquery of a SELECT.

    A :class:`.Subquery` is created by invoking the
    :meth:`_expression.SelectBase.subquery` method, or for convenience the
    :meth:`_expression.SelectBase.alias` method, on any
    :class:`_expression.SelectBase` subclass
    which includes :class:`_expression.Select`,
    :class:`_expression.CompoundSelect`, and
    :class:`_expression.TextualSelect`.  As rendered in a FROM clause,
    it represents the
    body of the SELECT statement inside of parenthesis, followed by the usual
    "AS <somename>" that defines all "alias" objects.

    The :class:`.Subquery` object is very similar to the
    :class:`_expression.Alias`
    object and can be used in an equivalent way.    The difference between
    :class:`_expression.Alias` and :class:`.Subquery` is that
    :class:`_expression.Alias` always
    contains a :class:`_expression.FromClause` object whereas
    :class:`.Subquery`
    always contains a :class:`_expression.SelectBase` object.

    .. versionadded:: 1.4 The :class:`.Subquery` class was added which now
       serves the purpose of providing an aliased version of a SELECT
       statement.

    rG   TNc                 j    t        j                  t        j                  |      j	                  |      S )z#Return a :class:`.Subquery` object.r   )r   r   r   SelectStatementRolerG   r  s      r:   r  zSubquery._factory
  s.     %%z

((
	r<   rC   ax  The :meth:`.Subquery.as_scalar` method, which was previously ``Alias.as_scalar()`` prior to version 1.4, is deprecated and will be removed in a future release; Please use the :meth:`_expression.Select.scalar_subquery` method of the :func:`_expression.select` construct before constructing a subquery object, or with the ORM use the :meth:`_query.Query.scalar_subquery` method.c                 \    | j                   j                  t              j                         S r6   )r  r  r  scalar_subqueryr8   s    r:   	as_scalarzSubquery.as_scalar
  s#     ||++,<=MMOOr<   c                 n    t        j                  dd       | j                  j                  ||||d      S )NzExecuting a subquery object is deprecated and will raise ObjectNotExecutableError in an upcoming release.  Please execute the underlying select() statement directly.rC   T)_force)r1   warn_deprecatedr  _execute_on_connection)r9   
connectionmultiparamsparamsexecution_optionss        r:   r  zSubquery._execute_on_connection
  sG     	B 		
 ||22V->t 3 
 	
r<   r6   )r=   r>   r?   rU   ru   _is_subqueryr@   r  r  r1   rw   r  r  rB   r<   r:   r  r  	  sX    8  NLM  T__	?	P	P
r<   r  c                       e Zd ZdZdej
                  fgZd Zd Ze	d        Z
e	d        Ze	d        Zd Zd	 Zd
 Ze	d        Ze	d        Zd Zd Zy)r%  z%Represent a grouping of a FROM clauser  c                 V    t        j                  t        j                  |      | _        y r6   )r   r   r   r   r  r9   r  s     r:   r  zFromGrouping.__init__0
  s     ''(<(<gFr<   c                      y r6   rB   r8   s    r:   r   zFromGrouping._init_collections3
      r<   c                 .    | j                   j                  S r6   )r  r   r8   s    r:   r   zFromGrouping.columns6
  s    ||###r<   c                 .    | j                   j                  S r6   )r  r   r8   s    r:   r   zFromGrouping.primary_key:
      ||'''r<   c                 .    | j                   j                  S r6   )r  r   r8   s    r:   r   zFromGrouping.foreign_keys>
      ||(((r<   c                 8    | j                   j                  |      S r6   )r  r   r  s     r:   r   zFromGrouping.is_derived_fromB
  s    ||++G44r<   c                 L    t         | j                  j                  di |      S NrB   )r%  r  rH   r9   r   s     r:   rH   zFromGrouping.aliasE
  s"    .DLL..4455r<   c                 L    t         | j                  j                  di |      S r#  )r%  r  r   r$  s     r:   r   z"FromGrouping._anonymous_fromclauseH
  s"    >DLL>>DDEEr<   c                 .    | j                   j                  S r6   )r  r  r8   s    r:   r  zFromGrouping._hide_fromsK
  r  r<   c                 .    | j                   j                  S r6   r  r   r8   s    r:   r   zFromGrouping._from_objectsO
      ||)))r<   c                     d| j                   iS Nr  r  r8   s    r:   __getstate__zFromGrouping.__getstate__S
  s    4<<((r<   c                     |d   | _         y r+  r  )r9   states     r:   __setstate__zFromGrouping.__setstate__V
  s    Y'r<   N)r=   r>   r?   rU   r.   r  r  r  r   rA   r   r   r   r   rH   r   r  r   r,  r/  rB   r<   r:   r%  r%  +
  s    /%'8'I'IJKG $ $ ( ( ) )56F ( ( * *)(r<   r%  c                   j    e Zd ZdZdZdej                  fdej                  fdej                  fgZdZ	dZ
	 dZ	  fd	Zd
 Zd Zd Zej"                  d        Zd Z ej(                  d      dd       Z ej(                  d      dd       Z ej(                  d      dd       Zed        Z xZS )TableClausea-  Represents a minimal "table" construct.

    This is a lightweight table object that has only a name, a
    collection of columns, which are typically produced
    by the :func:`_expression.column` function, and a schema::

        from sqlalchemy import table, column

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

    The :class:`_expression.TableClause` construct serves as the base for
    the more commonly used :class:`_schema.Table` object, providing
    the usual set of :class:`_expression.FromClause` services including
    the ``.c.`` collection and statement generation methods.

    It does **not** provide all the additional schema-level services
    of :class:`_schema.Table`, including constraints, references to other
    tables, or support for :class:`_schema.MetaData`-level services.
    It's useful
    on its own as an ad-hoc construct used to generate quick SQL
    statements when a more fully fledged :class:`_schema.Table`
    is not on hand.

    r7  r   rf   r  TFNc                    t         t        |           || _        t	               | _        t               | _        t               | _	        |D ]  }| j                  |        |j                  dd      }||| _        | j                  !| j                  d| j                  | _        n| j                  | _        |r!t        j                  dt!        |      z        y)a  Produce a new :class:`_expression.TableClause`.

        The object returned is an instance of
        :class:`_expression.TableClause`, which
        represents the "syntactical" portion of the schema-level
        :class:`_schema.Table` object.
        It may be used to construct lightweight table constructs.

        .. versionchanged:: 1.0.0 :func:`_expression.table` can now
           be imported from the plain ``sqlalchemy`` namespace like any
           other SQL element.


        :param name: Name of the table.

        :param columns: A collection of :func:`_expression.column` constructs.

        :param schema: The schema name for this table.

            .. versionadded:: 1.3.18 :func:`_expression.table` can now
               accept a ``schema`` argument.
        r  N.r   )r?  r1  r  rf   r   r   r   r   r   r   append_columnr   r  fullnamer0   r   rQ  )r9   rf   r   r   r   r  r   s         r:   r  zTableClause.__init__
  s    0 	k4)+	.0$;E 	"Aq!	" $' DK;;"'+{{DII>DM IIDM##$ADH$LMM r<   c                 j    | j                   | j                   dz   | j                  z   S | j                  S )Nr3  )r  rf   r8   s    r:   __str__zTableClause.__str__
  s.    ;;";;$tyy0099r<   c                      y r6   rB   r]   s     r:   r_   z#TableClause._refresh_for_new_column
  r  r<   c                      y r6   rB   r8   s    r:   r   zTableClause._init_collections
  r  r<   c                 r    t         j                  r| j                  S | j                  j                  dd      S )Nr  r  )r1   r  rf   r  r8   s    r:   r   zTableClause.description
  s+    999999##G-?@@r<   c                     |j                   }|*|| ur&t        j                  d|j                  d|d      | j                  j                  |       | |_         y )Nzcolumn object 'z' already assigned to table '')r7  r0   r   r   r   add)r9   r   r   existings       r:   r4  zTableClause.append_column
  sT    77HD$8##55($ 
 	!r<   zsqlalchemy.sql.dmlc                 \    t        j                  j                  j                  | f||d|S )zGenerate an :func:`_expression.insert` construct against this
        :class:`_expression.TableClause`.

        E.g.::

            table.insert().values(name='foo')

        See :func:`_expression.insert` for argument and usage information.

        )rR  inline)r1   rk   sql_dmlInsert)r9   rR  r@  rJ   s       r:   insertzTableClause.insert
  s6     ~~%%,,

28
 	
r<   c                 ^    t        j                  j                  j                  | f|||d|S )a  Generate an :func:`_expression.update` construct against this
        :class:`_expression.TableClause`.

        E.g.::

            table.update().where(table.c.id==7).values(name='foo')

        See :func:`_expression.update` for argument and usage information.

        )r   rR  r@  )r1   rk   rA  Update)r9   r   rR  r@  rJ   s        r:   r/  zTableClause.update
  s<     ~~%%,,
#	

 
 	
r<   c                 X    t        j                  j                  j                  | |fi |S )zGenerate a :func:`_expression.delete` construct against this
        :class:`_expression.TableClause`.

        E.g.::

            table.delete().where(table.c.id==7)

        See :func:`_expression.delete` for argument and usage information.

        )r1   rk   rA  Deleter   s      r:   deletezTableClause.delete
  s&     ~~%%,,T;I&IIr<   c                     | gS r6   rB   r8   s    r:   r   zTableClause._from_objects  r  r<   r  r  r6   )r=   r>   r?   rU   ru   r.   )dp_fromclause_canonical_column_collection	dp_stringr  r  implicit_returning_autoincrement_columnr  r7  r_   r   r1   r
  r   r4  rx   rC  r/  rH  rA   r   r  r  s   @r:   r1  r1  Z
  s   : N GG	
 
",,-	$../ = !>(NT 
A A	 T-.
 /
 T-.
 /
& T-.J /J  r<   r1  c                       e Zd Zdej                  fdej
                  fdej
                  fdej
                  fgZed        Zd Z	d Z
d Z	 	 	 	 	 dd
Zy	)ForUpdateArgofnowaitreadskip_lockedc                 b    t        |t              r|S |dv ry |du r
t               S t        di |S )Nr  TrB   )r6  rO  )r  with_for_updates     r:   _from_argumentzForUpdateArg._from_argument  s;    o|4""-$>!2/22r<   c                 .   t        |t              xr |j                  | j                  k(  xri |j                  | j                  k(  xrN |j                  | j                  k(  xr3 |j
                  | j
                  k(  xr |j                  | j                  u S r6   )r6  rO  rQ  rR  rS  	key_sharerP  r   s     r:   __eq__zForUpdateArg.__eq__  s    ul+ $+$

dii'$ !!T%5%55$ 4>>1	$
 DGG#	
r<   c                 &    | j                  |       S r6   )rY  r   s     r:   __ne__zForUpdateArg.__ne__)  s    ;;u%%%r<   c                     t        |       S r6   )r!  r8   s    r:   __hash__zForUpdateArg.__hash__,  s    $xr<   Nc                     || _         || _        || _        || _        |Kt	        j
                  |      D cg c]&  }t        j                  t        j                  |      ( c}| _
        yd| _
        yc c}w )zZRepresents arguments specified to
        :meth:`_expression.Select.for_update`.

        N)rQ  rR  rS  rX  r1   to_listr   r   r   ColumnsClauseRolerP  )r9   rQ  rR  rP  rS  rX  elems          r:   r  zForUpdateArg.__init__/  sl     	&"> !LL,   !8!8$?DG
 DGs   +A2FFNFF)r=   r>   r?   r.   r  r  r  r  rV  rY  r[  r]  r  rB   r<   r:   rO  rO    s    	 667	$//0	"--.	)445	 3 3
&
 r<   rO  c                        e Zd ZdZdZdZdZdej                  fdej                  fdej                  fdej                  fgZ fd	Zed
        Zed        Zedd       Zed        Zd Zed        Z xZS )ValueszRepresent a ``VALUES`` construct that can be used as a FROM element
    in a statement.

    The :class:`_expression.Values` object is created from the
    :func:`_expression.values` function.

    .. versionadded:: 1.4

    TrR  rB   _column_args_datarf   literal_bindsc                     t         t        |           || _        |j	                  dd      | _        |j	                  dd      | _        | j
                  du| _        y)a  Construct a :class:`_expression.Values` construct.

        The column expressions and the actual data for
        :class:`_expression.Values` are given in two separate steps.  The
        constructor receives the column expressions typically as
        :func:`_expression.column` constructs,
        and the data is then passed via the
        :meth:`_expression.Values.data` method as a list,
        which can be called multiple
        times to add more data, e.g.::

            from sqlalchemy import column
            from sqlalchemy import values

            value_expr = values(
                column('id', Integer),
                column('name', String),
                name="my_values"
            ).data(
                [(1, 'name1'), (2, 'name2'), (3, 'name3')]
            )

        :param \*columns: column expressions, typically composed using
         :func:`_expression.column` objects.

        :param name: the name for this VALUES construct.  If omitted, the
         VALUES construct will be unnamed in a SQL expression.   Different
         backends may have different requirements here.

        :param literal_binds: Defaults to False.  Whether or not to render
         the data values inline in the SQL output, rather than using bound
         parameters.

        rf   Nrg  F)r?  rd  r  re  r   rf   rg  r  )r9   r   r   r   s      r:   r  zValues.__init__`  sQ    H 	fd$&#FF64(	VVOU;!%$!6r<   c                 T    | j                   D cg c]  }|j                   c}S c c}w r6   )re  type)r9   r   s     r:   _column_typeszValues._column_types  s     $($5$56S666s   %c                 8    || _         | j                   du| _        y)aY  Return a new :class:`_expression.Values`
        construct that is a copy of this
        one with the given name.

        This method is a VALUES-specific specialization of the
        :meth:`_expression.FromClause.alias` method.

        .. seealso::

            :ref:`tutorial_using_aliases`

            :func:`_expression.alias`

        N)rf   r  )r9   rf   r   s      r:   rH   zValues.alias  s      	!%$!6r<   c                 &    d| _         ||| _        yy)zReturn a new :class:`_expression.Values` with the lateral flag set,
        so that
        it renders as LATERAL.

        .. seealso::

            :func:`_expression.lateral`

        TN)rY   rf   re   s     r:   rg   zValues.lateral  s      DI r<   c                 0    | xj                   |fz  c_         y)ar  Return a new :class:`_expression.Values` construct,
        adding the given data
        to the data list.

        E.g.::

            my_values = my_values.data([(1, 'value 1'), (2, 'value2')])

        :param values: a sequence (i.e. list) of tuples that map to the
         column expressions given in the :class:`_expression.Values`
         constructor.

        N)rf  )r9   rR  s     r:   datazValues.data  s      	

vi
r<   c                 j    | j                   D ]$  }| j                  j                  |       | |_        & y r6   )re  r   r=  r7  )r9   r   s     r:   r   z"Values._populate_column_collection  s0    "" 	AMMa AG	r<   c                     | gS r6   rB   r8   s    r:   r   zValues._from_objects  r  r<   r6   )r=   r>   r?   rU   r  ru   rf  r.   r  dp_dml_multi_valuesrK  r  r  r  rA   rk  r   rH   rg   ro  r   r   r  r  s   @r:   rd  rd  I  s     NE 
*@@A	#778	",,-	+667	(7T 7 7 7 7$      "
  r<   rd  c                   h   e Zd ZdZdZdZd Zd Zed        Z	ed        Z
ed        Ze ej                  dd	      d
               Zed        Z ej                  dd      d        Zej$                  d        Z ej                  dd      d        Zd Zd Zd ZddZed        ZddZd ZddZy)
SelectBasezBase class for SELECT statements.


    This includes :class:`_expression.Select`,
    :class:`_expression.CompoundSelect` and
    :class:`_expression.TextualSelect`.


    Tc                     t               r6   rP   r   s     r:   r   z.SelectBase._generate_fromclause_column_proxies  r`   r<   c                 $    | j                          y r6   )rA  r]   s     r:   r_   z"SelectBase._refresh_for_new_column  s      "r<   c                     t               )a$  A :class:`_expression.ColumnCollection`
        representing the columns that
        this SELECT statement or similar construct returns in its result set.

        This collection differs from the :attr:`_expression.FromClause.columns`
        collection of a :class:`_expression.FromClause` in that the columns
        within this collection cannot be directly nested inside another SELECT
        statement; a subquery must be applied first which provides for the
        necessary parenthesization required by SQL.

        .. note::

            The :attr:`_sql.SelectBase.selected_columns` collection does not
            include expressions established in the columns clause using the
            :func:`_sql.text` construct; these are silently omitted from the
            collection. To use plain textual column expressions inside of a
            :class:`_sql.Select` construct, use the :func:`_sql.literal_column`
            construct.

        .. seealso::

            :attr:`_sql.Select.selected_columns`

        .. versionadded:: 1.4

        rP   r8   s    r:   selected_columnszSelectBase.selected_columns  s    8 "##r<   c                     t               )a  A sequence of expressions that correspond to what is rendered
        in the columns clause, including :class:`_sql.TextClause`
        constructs.

        .. versionadded:: 1.4.12

        .. seealso::

            :attr:`_sql.SelectBase.exported_columns`

        rP   r8   s    r:   rR   z SelectBase._all_selected_columns  s     "##r<   c                     | j                   S )af  A :class:`_expression.ColumnCollection`
        that represents the "exported"
        columns of this :class:`_expression.Selectable`, not including
        :class:`_sql.TextClause` constructs.

        The "exported" columns for a :class:`_expression.SelectBase`
        object are synonymous
        with the :attr:`_expression.SelectBase.selected_columns` collection.

        .. versionadded:: 1.4

        .. seealso::

            :attr:`_expression.Select.exported_columns`

            :attr:`_expression.Selectable.exported_columns`

            :attr:`_expression.FromClause.exported_columns`


        )rx  r8   s    r:   rT   zSelectBase.exported_columns  s    . $$$r<   rC   a  The :attr:`_expression.SelectBase.c` and :attr:`_expression.SelectBase.columns` attributes are deprecated and will be removed in a future release; these attributes implicitly create a subquery that should be explicit.  Please call :meth:`_expression.SelectBase.subquery` first in order to create a subquery, which then contains this attribute.  To access the columns that this SELECT object SELECTs from, use the :attr:`_expression.SelectBase.selected_columns` attribute.c                 .    | j                   j                  S r6   )_implicit_subqueryr   r8   s    r:   r   zSelectBase.c/  s     &&...r<   c                     | j                   S r6   )r   r8   s    r:   r   zSelectBase.columns@  s    vvr<   a   The :meth:`_expression.SelectBase.select` method is deprecated and will be removed in a future release; this method implicitly creates a subquery that should be explicit.  Please call :meth:`_expression.SelectBase.subquery` first in order to create a subquery, which then can be selected.c                 :     | j                   j                  |i |S r6   )r|  r   r  s      r:   r   zSelectBase.selectD  s"     .t&&--s9b99r<   c                 "    | j                         S r6   rG   r8   s    r:   r|  zSelectBase._implicit_subqueryP  s    }}r<   zThe :meth:`_expression.SelectBase.as_scalar` method is deprecated and will be removed in a future release.  Please refer to :meth:`_expression.SelectBase.scalar_subquery`.c                 "    | j                         S r6   )r  r8   s    r:   r  zSelectBase.as_scalarT  s     ##%%r<   c                     t        |       S )aa  Return an :class:`_sql.Exists` representation of this selectable,
        which can be used as a column expression.

        The returned object is an instance of :class:`_sql.Exists`.

        .. seealso::

            :func:`_sql.exists`

            :ref:`tutorial_exists` - in the :term:`2.0 style` tutorial.

        .. versionadded:: 1.4

        )Existsr8   s    r:   existszSelectBase.exists^  s     d|r<   c                 f    | j                   t        ur| j                  t              } t        |       S )aX  Return a 'scalar' representation of this selectable, which can be
        used as a column expression.

        The returned object is an instance of :class:`_sql.ScalarSelect`.

        Typically, a select statement which has only one column in its columns
        clause is eligible to be used as a scalar expression.  The scalar
        subquery can then be used in the WHERE clause or columns clause of
        an enclosing SELECT.

        Note that the scalar subquery differentiates from the FROM-level
        subquery that can be produced using the
        :meth:`_expression.SelectBase.subquery`
        method.

        .. versionchanged: 1.4 - the ``.as_scalar()`` method was renamed to
           :meth:`_expression.SelectBase.scalar_subquery`.

        .. seealso::

            :ref:`tutorial_scalar_subquery` - in the 2.0 tutorial

        )_label_styler  r  ScalarSelectr8   s    r:   r  zSelectBase.scalar_subqueryo  s/    0 $44''(89DD!!r<   c                 @    | j                         j                  |      S )zReturn a 'scalar' representation of this selectable, embedded as a
        subquery with a label.

        .. seealso::

            :meth:`_expression.SelectBase.as_scalar`.

        )r  labelre   s     r:   r  zSelectBase.label  s     ##%++D11r<   Nc                 .    t         j                  | |      S rb   )rc   r  re   s     r:   rg   zSelectBase.lateral  s     d++r<   c                     | gS r6   rB   r8   s    r:   r   zSelectBase._from_objects  r  r<   c                 J    t         j                  | j                         |      S )a  Return a subquery of this :class:`_expression.SelectBase`.

        A subquery is from a SQL perspective a parenthesized, named
        construct that can be placed in the FROM clause of another
        SELECT statement.

        Given a SELECT statement such as::

            stmt = select(table.c.id, table.c.name)

        The above statement might look like::

            SELECT table.id, table.name FROM table

        The subquery form by itself renders the same way, however when
        embedded into the FROM clause of another SELECT statement, it becomes
        a named sub-element::

            subq = stmt.subquery()
            new_stmt = select(subq)

        The above renders as::

            SELECT anon_1.id, anon_1.name
            FROM (SELECT table.id, table.name FROM table) AS anon_1

        Historically, :meth:`_expression.SelectBase.subquery`
        is equivalent to calling
        the :meth:`_expression.FromClause.alias`
        method on a FROM object; however,
        as a :class:`_expression.SelectBase`
        object is not directly  FROM object,
        the :meth:`_expression.SelectBase.subquery`
        method provides clearer semantics.

        .. versionadded:: 1.4

        )r  rd   _ensure_disambiguated_namesre   s     r:   rG   zSelectBase.subquery  s!    P ""4#C#C#EtLLr<   c                     t               )ztEnsure that the names generated by this selectbase will be
        disambiguated in some way, if possible.

        rP   r8   s    r:   r  z&SelectBase._ensure_disambiguated_names  s     "##r<   c                 &    | j                  |      S )a.  Return a named subquery against this
        :class:`_expression.SelectBase`.

        For a :class:`_expression.SelectBase` (as opposed to a
        :class:`_expression.FromClause`),
        this returns a :class:`.Subquery` object which behaves mostly the
        same as the :class:`_expression.Alias` object that is used with a
        :class:`_expression.FromClause`.

        .. versionchanged:: 1.4 The :meth:`_expression.SelectBase.alias`
           method is now
           a synonym for the :meth:`_expression.SelectBase.subquery` method.

        r   r  r   s      r:   rH   zSelectBase.alias  s     }}$}''r<   r6   r  )r=   r>   r?   rU   rX   	is_selectr   r_   rA   rx  rR   rT   r1   rw   r   r   r   r   r  r|  r  r  r  r  rg   r   rG   r  rH   rB   r<   r:   rt  rt    s>     I$# $ $: $ $ % %0 T__		/ /   T__	2:: ## $ T__	:&&"":	2,  (MT$(r<   rt  c                       e Zd ZdZdZdej                  fgZdZd Z	d Z
d Zd Zed	        Zed
        ZddZd Zd Zd Zed        Zed        Zed        Zy)SelectStatementGroupingzRepresent a grouping of a :class:`_expression.SelectBase`.

    This differs from :class:`.Subquery` in that we are still
    an "inner" SELECT statement, this is strictly for grouping inside of
    compound selects.

    select_statement_groupingr  Tc                 V    t        j                  t        j                  |      | _        y r6   )r   r   r   r
  r  r  s     r:   r  z SelectStatementGrouping.__init__  s     ''(A(A7Kr<   c                 l    | j                   j                         }|| j                   urt        |      S | S r6   )r  r  r  )r9   new_elements     r:   r  z3SelectStatementGrouping._ensure_disambiguated_names  s0    ll>>@dll**;77Kr<   c                     | j                   S r6   r  r8   s    r:   get_label_stylez'SelectStatementGrouping.get_label_style  s       r<   c                 J    t        | j                  j                  |            S r6   )r  r  r  )r9   label_styles     r:   r  z'SelectStatementGrouping.set_label_style	  s!    &LL((5
 	
r<   c                 .    | j                   j                  S r6   )r  r  r8   s    r:   r  z$SelectStatementGrouping._label_style  r   r<   c                     | j                   S r6   r  r8   s    r:   select_statementz(SelectStatementGrouping.select_statement  s    ||r<   Nc                     | S r6   rB   r&  s     r:   r  z"SelectStatementGrouping.self_group      r<   c                 8    | j                   j                  |      S r6   )r  _generate_columns_plus_names)r9   anon_for_dupe_keys     r:   r  z4SelectStatementGrouping._generate_columns_plus_names  s    ||889JKKr<   c                 :    | j                   j                  |       y r6   r  )r9   rG   s     r:   r   z;SelectStatementGrouping._generate_fromclause_column_proxies  s    88Br<   c                 8    | j                   j                  |      S r6   )r  _generate_proxy_for_new_column)r9   r^   rG   s      r:   r  z6SelectStatementGrouping._generate_proxy_for_new_column  s    ||::8DDr<   c                 .    | j                   j                  S r6   )r  rR   r8   s    r:   rR   z-SelectStatementGrouping._all_selected_columns"  s    ||111r<   c                 .    | j                   j                  S )a:  A :class:`_expression.ColumnCollection`
        representing the columns that
        the embedded SELECT statement returns in its result set, not including
        :class:`_sql.TextClause` constructs.

        .. versionadded:: 1.4

        .. seealso::

            :attr:`_sql.Select.selected_columns`

        )r  rx  r8   s    r:   rx  z(SelectStatementGrouping.selected_columns&  s     ||,,,r<   c                 .    | j                   j                  S r6   r(  r8   s    r:   r   z%SelectStatementGrouping._from_objects6  r)  r<   r6   )r=   r>   r?   rU   ru   r.   r  r  _is_select_containerr  r  r  r  rA   r  r  r  r  r   r  rR   rx  r   rB   r<   r:   r  r    s     1N%'8'I'IJKL!

 ) )  LCE 2 2 - - * *r<   r  c                   t    e Zd ZdZ ej
                  dd      d        Z ej
                  dd      d        Zy)DeprecatedSelectBaseGenerationszA collection of methods available on :class:`_sql.Select` and
    :class:`_sql.CompoundSelect`, these are all **deprecated** methods as they
    modify the object in-place.

    rC   zThe :meth:`_expression.GenerativeSelect.append_order_by` method is deprecated and will be removed in a future release.  Use the generative method :meth:`_expression.GenerativeSelect.order_by`.c                 >     | j                   j                  | g|  y)a  Append the given ORDER BY criterion applied to this selectable.

        The criterion will be appended to any pre-existing ORDER BY criterion.

        This is an **in-place** mutation method; the
        :meth:`_expression.GenerativeSelect.order_by` method is preferred,
        as it
        provides standard :term:`method chaining`.

        .. seealso::

            :meth:`_expression.GenerativeSelect.order_by`

        N)order_bynon_generativer9   clausess     r:   append_order_byz/DeprecatedSelectBaseGenerations.append_order_byB  s    , 	%$$T4G4r<   zThe :meth:`_expression.GenerativeSelect.append_group_by` method is deprecated and will be removed in a future release.  Use the generative method :meth:`_expression.GenerativeSelect.group_by`.c                 >     | j                   j                  | g|  y)a\  Append the given GROUP BY criterion applied to this selectable.

        The criterion will be appended to any pre-existing GROUP BY criterion.

        This is an **in-place** mutation method; the
        :meth:`_expression.GenerativeSelect.group_by` method is preferred,
        as it
        provides standard :term:`method chaining`.


        N)group_byr  r  s     r:   append_group_byz/DeprecatedSelectBaseGenerations.append_group_byZ  s    & 	%$$T4G4r<   N)r=   r>   r?   rU   r1   rw   r  r  rB   r<   r:   r  r  ;  sU     T__	955" T__	955r<   r  c                      e Zd ZdZdZdZdZdZdZdZ	dZ
 ej                  d      eddddddfd       Ze	 	 	 	 	 dd       Zd	 Zd
 Z ej&                  dd      d        Zed        Zed        ZddZd Zed        Zd Zed        Zed        Zed        Zed d       Zed        Z e ejB                  d      d               Z"ed        Z#ed        Z$y)!GenerativeSelecta&  Base class for SELECT statements where additional elements can be
    added.

    This serves as the base for :class:`_expression.Select` and
    :class:`_expression.CompoundSelect`
    where elements such as ORDER BY, GROUP BY can be added and column
    rendering can be controlled.  Compare to
    :class:`_expression.TextualSelect`, which,
    while it subclasses :class:`_expression.SelectBase`
    and is also a SELECT construct,
    represents a fixed textual string which cannot be altered at this level,
    only wrapped as a subquery.

    rB   N)r   z^The :paramref:`_sql.select.bind` argument is deprecated and will be removed in SQLAlchemy 2.0.)r  Fc                    |r-t         j                  rt        j                  dd       t        }|| _        || j
                  j                  | |       || j                  j                  | |       |0 | j                  j                  | gt        j                  |        |0 | j                  j                  | gt        j                  |        || _        y )NzThe use_labels=True keyword argument to GenerativeSelect is deprecated and will be removed in version 2.0. Please use select.set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL) if you need to replicate this legacy behavior.   
stacklevel)r1   SQLALCHEMY_WARN_20warn_deprecated_20r  r  limitr  offsetr  r_  r  _bind)r9   r  
use_labelsr  r  r  r  r  s           r:   r  zGenerativeSelect.__init__  s    " &&''E
  ! :L(JJ%%dE2KK&&tV4(DMM((GX0FG(DMM((GX0FG
r<   c                 .    t        |||||      | _        y)a  Specify a ``FOR UPDATE`` clause for this
        :class:`_expression.GenerativeSelect`.

        E.g.::

            stmt = select(table).with_for_update(nowait=True)

        On a database like PostgreSQL or Oracle, the above would render a
        statement like::

            SELECT table.a, table.b FROM table FOR UPDATE NOWAIT

        on other backends, the ``nowait`` option is ignored and instead
        would produce::

            SELECT table.a, table.b FROM table FOR UPDATE

        When called with no arguments, the statement will render with
        the suffix ``FOR UPDATE``.   Additional arguments can then be
        provided which allow for common database-specific
        variants.

        :param nowait: boolean; will render ``FOR UPDATE NOWAIT`` on Oracle
         and PostgreSQL dialects.

        :param read: boolean; will render ``LOCK IN SHARE MODE`` on MySQL,
         ``FOR SHARE`` on PostgreSQL.  On PostgreSQL, when combined with
         ``nowait``, will render ``FOR SHARE NOWAIT``.

        :param of: SQL expression or list of SQL expression elements
         (typically :class:`_schema.Column`
         objects or a compatible expression) which
         will render into a ``FOR UPDATE OF`` clause; supported by PostgreSQL
         and Oracle.  May render as a table or as a column depending on
         backend.

        :param skip_locked: boolean, will render ``FOR UPDATE SKIP LOCKED``
         on Oracle and PostgreSQL dialects or ``FOR SHARE SKIP LOCKED`` if
         ``read=True`` is also specified.

        :param key_share: boolean, will render ``FOR NO KEY UPDATE``,
         or if combined with ``read=True`` will render ``FOR KEY SHARE``,
         on the PostgreSQL dialect.

        )rQ  rR  rP  rS  rX  N)rO  _for_update_arg)r9   rQ  rR  rP  rS  rX  s         r:   rU  z GenerativeSelect.with_for_update  s!    l  ,# 
r<   c                     | j                   S )zS
        Retrieve the current label style.

        .. versionadded:: 1.4

        r  r8   s    r:   r  z GenerativeSelect.get_label_style  s        r<   c                 P    | j                   |ur| j                         } || _         | S )a8  Return a new selectable with the specified label style.

        There are three "label styles" available,
        :data:`_sql.LABEL_STYLE_DISAMBIGUATE_ONLY`,
        :data:`_sql.LABEL_STYLE_TABLENAME_PLUS_COL`, and
        :data:`_sql.LABEL_STYLE_NONE`.   The default style is
        :data:`_sql.LABEL_STYLE_TABLENAME_PLUS_COL`.

        In modern SQLAlchemy, there is not generally a need to change the
        labeling style, as per-expression labels are more effectively used by
        making use of the :meth:`_sql.ColumnElement.label` method. In past
        versions, :data:`_sql.LABEL_STYLE_TABLENAME_PLUS_COL` was used to
        disambiguate same-named columns from different tables, aliases, or
        subqueries; the newer :data:`_sql.LABEL_STYLE_DISAMBIGUATE_ONLY` now
        applies labels only to names that conflict with an existing name so
        that the impact of this labeling is minimal.

        The rationale for disambiguation is mostly so that all column
        expressions are available from a given :attr:`_sql.FromClause.c`
        collection when a subquery is created.

        .. versionadded:: 1.4 - the
            :meth:`_sql.GenerativeSelect.set_label_style` method replaces the
            previous combination of ``.apply_labels()``, ``.with_labels()`` and
            ``use_labels=True`` methods and/or parameters.

        .. seealso::

            :data:`_sql.LABEL_STYLE_DISAMBIGUATE_ONLY`

            :data:`_sql.LABEL_STYLE_TABLENAME_PLUS_COL`

            :data:`_sql.LABEL_STYLE_NONE`

            :data:`_sql.LABEL_STYLE_DEFAULT`

        )r  	_generater9   styles     r:   r  z GenerativeSelect.set_label_style  s,    L E)>>#D %Dr<   z*:meth:`_sql.GenerativeSelect.apply_labels`z<Use set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL) instead.r  c                 ,    | j                  t              S r6   )r  r  r8   s    r:   apply_labelszGenerativeSelect.apply_labels%  s     ##$BCCr<   c                 ^    t        j                  t        j                  | j                        S )z9ClauseList access to group_by_clauses for legacy dialects)r'   _construct_rawr   comma_op_group_by_clausesr8   s    r:   _group_by_clausez!GenerativeSelect._group_by_clause-  (     (( 6 6
 	
r<   c                 ^    t        j                  t        j                  | j                        S )z9ClauseList access to order_by_clauses for legacy dialects)r'   r  r   r  _order_by_clausesr8   s    r:   _order_by_clausez!GenerativeSelect._order_by_clause4  r  r<   c                 P    t        j                  t        j                  |||      S )zConvert the given value to an "offset or limit" clause.

        This handles incoming integers and converts to an expression; if
        an expression is already given, it is passed through.

        )rf   type_)r   r   r   LimitOffsetRole)r9   r  rf   r  s       r:   _offset_or_limit_clausez(GenerativeSelect._offset_or_limit_clause;  s&     !!7U
 	
r<   c                     |y	 |j                   }t        j                  |      S # t        $ r7}t        j                  t        j                  d|z        |       Y d}~yd}~ww xY w)zConvert the "offset or limit" clause of a select construct to an
        integer.

        This is only possible if the value is stored as a simple bound
        parameter. Otherwise, a compilation error is raised.

        Nz@This SELECT structure does not use a simple integer value for %s)replace_context)r;   r1   asintAttributeErrorraise_r0   CompileError)r9   clauseattrnamevalueerrs        r:   _offset_or_limit_clause_asintz.GenerativeSelect._offset_or_limit_clause_asintF  sp     >	%..E ::e$$  	KK  +-56 !$ 	s   & 	A&-A!!A&c                 :    | j                  | j                  d      S )zGet an integer value for the limit.  This should only be used
        by code that cannot support a limit as a BindParameter or
        other custom clause as it will throw an exception if the limit
        isn't currently set to an integer.

        r  )r  _limit_clauser8   s    r:   _limitzGenerativeSelect._limit]  s     11$2D2DgNNr<   c                 "    t        |t              S )zkTrue if the clause is a simple integer, False
        if it is not present or is a SQL expression.
        )r6  r4   r9   r  s     r:   _simple_int_clausez#GenerativeSelect._simple_int_clauseg  s     &"344r<   c                 :    | j                  | j                  d      S )zGet an integer value for the offset.  This should only be used
        by code that cannot support an offset as a BindParameter or
        other custom clause as it will throw an exception if the
        offset isn't currently set to an integer.

        r  )r  _offset_clauser8   s    r:   _offsetzGenerativeSelect._offsetm  s"     11
 	
r<   c                 ^    | j                   d uxs | j                  d uxs | j                  d uS r6   )r  r  _fetch_clauser8   s    r:   _has_row_limiting_clausez)GenerativeSelect._has_row_limiting_clausey  s=     d* .""$..!!-	
r<   c                 L    dx| _         | _        | j                  |      | _        y)af  Return a new selectable with the given LIMIT criterion
        applied.

        This is a numerical value which usually renders as a ``LIMIT``
        expression in the resulting select.  Backends that don't
        support ``LIMIT`` will attempt to provide similar
        functionality.

        .. note::

           The :meth:`_sql.GenerativeSelect.limit` method will replace
           any clause applied with :meth:`_sql.GenerativeSelect.fetch`.

        .. versionchanged:: 1.0.0 - :meth:`_expression.Select.limit` can now
           accept arbitrary SQL expressions as well as integer values.

        :param limit: an integer LIMIT parameter, or a SQL expression
         that provides an integer result. Pass ``None`` to reset it.

        .. seealso::

           :meth:`_sql.GenerativeSelect.fetch`

           :meth:`_sql.GenerativeSelect.offset`

        N)r  _fetch_clause_optionsr  r  )r9   r  s     r:   r  zGenerativeSelect.limit  s'    : ;?>T7!99%@r<   c                 t    d| _         |dx| _        | _        y| j                  |      | _        ||d| _        y)a  Return a new selectable with the given FETCH FIRST criterion
        applied.

        This is a numeric value which usually renders as
        ``FETCH {FIRST | NEXT} [ count ] {ROW | ROWS} {ONLY | WITH TIES}``
        expression in the resulting select. This functionality is
        is currently implemented for Oracle, PostgreSQL, MSSQL.

        Use :meth:`_sql.GenerativeSelect.offset` to specify the offset.

        .. note::

           The :meth:`_sql.GenerativeSelect.fetch` method will replace
           any clause applied with :meth:`_sql.GenerativeSelect.limit`.

        .. versionadded:: 1.4

        :param count: an integer COUNT parameter, or a SQL expression
         that provides an integer result. When ``percent=True`` this will
         represent the percentage of rows to return, not the absolute value.
         Pass ``None`` to reset it.

        :param with_ties: When ``True``, the WITH TIES option is used
         to return any additional rows that tie for the last place in the
         result set according to the ``ORDER BY`` clause. The
         ``ORDER BY`` may be mandatory in this case. Defaults to ``False``

        :param percent: When ``True``, ``count`` represents the percentage
         of the total number of selected rows to return. Defaults to ``False``

        .. seealso::

           :meth:`_sql.GenerativeSelect.limit`

           :meth:`_sql.GenerativeSelect.offset`

        N)	with_tiespercent)r  r  r  r  )r9   countr  r  s       r:   fetchzGenerativeSelect.fetch  sE    P "=>BBD!;!%!=!=e!DD&"*D&r<   c                 0    | j                  |      | _        y)a  Return a new selectable with the given OFFSET criterion
        applied.


        This is a numeric value which usually renders as an ``OFFSET``
        expression in the resulting select.  Backends that don't
        support ``OFFSET`` will attempt to provide similar
        functionality.


        .. versionchanged:: 1.0.0 - :meth:`_expression.Select.offset` can now
           accept arbitrary SQL expressions as well as integer values.

        :param offset: an integer OFFSET parameter, or a SQL expression
         that provides an integer result. Pass ``None`` to reset it.

        .. seealso::

           :meth:`_sql.GenerativeSelect.limit`

           :meth:`_sql.GenerativeSelect.fetch`

        N)r  r  )r9   r  s     r:   r  zGenerativeSelect.offset  s    4 #::6Br<   ri   c                     t         j                  j                  }dx| _        | _        |j                  | j                  | j                  ||      \  | _        | _        y)a  Apply LIMIT / OFFSET to this statement based on a slice.

        The start and stop indices behave like the argument to Python's
        built-in :func:`range` function. This method provides an
        alternative to using ``LIMIT``/``OFFSET`` to get a slice of the
        query.

        For example, ::

            stmt = select(User).order_by(User).id.slice(1, 3)

        renders as

        .. sourcecode:: sql

           SELECT users.id AS users_id,
                  users.name AS users_name
           FROM users ORDER BY users.id
           LIMIT ? OFFSET ?
           (2, 1)

        .. note::

           The :meth:`_sql.GenerativeSelect.slice` method will replace
           any clause applied with :meth:`_sql.GenerativeSelect.fetch`.

        .. versionadded:: 1.4  Added the :meth:`_sql.GenerativeSelect.slice`
           method generalized from the ORM.

        .. seealso::

           :meth:`_sql.GenerativeSelect.limit`

           :meth:`_sql.GenerativeSelect.offset`

           :meth:`_sql.GenerativeSelect.fetch`

        N)r1   rk   rl   r  r  _make_slicer  r  )r9   startstoprl   s       r:   slicezGenerativeSelect.slice  sT    R >>**:>>T72:2F2F 3 3UD3
/D/r<   c                     t        |      dk(  r|d   d| _        y| xj                  t        d |D              z  c_        y)a  Return a new selectable with the given list of ORDER BY
        criteria applied.

        e.g.::

            stmt = select(table).order_by(table.c.id, table.c.name)

        Calling this method multiple times is equivalent to calling it once
        with all the clauses concatenated. All existing ORDER BY criteria may
        be cancelled by passing ``None`` by itself.  New ORDER BY criteria may
        then be added by invoking :meth:`_orm.Query.order_by` again, e.g.::

            # will erase all ORDER BY and ORDER BY new_col alone
            stmt = stmt.order_by(None).order_by(new_col)

        :param \*clauses: a series of :class:`_expression.ColumnElement`
         constructs
         which will be used to generate an ORDER BY clause.

        .. seealso::

            :ref:`tutorial_order_by` - in the :ref:`unified_tutorial`

            :ref:`tutorial_order_by_label` - in the :ref:`unified_tutorial`

        r   r   NrB   c              3   d   K   | ](  }t        j                  t        j                  |       * y wr6   )r   r   r   OrderByRoler   r  s     r:   r   z,GenerativeSelect.order_by.<locals>.<genexpr>>  +      ,   !2!2F;,   .0)rN  r  r   r  s     r:   r  zGenerativeSelect.order_by  sF    : w<1!3%'D"""e ,%, ' "r<   c                     t        |      dk(  r|d   d| _        y| xj                  t        d |D              z  c_        y)a~  Return a new selectable with the given list of GROUP BY
        criterion applied.

        All existing GROUP BY settings can be suppressed by passing ``None``.

        e.g.::

            stmt = select(table.c.name, func.max(table.c.stat)).\
            group_by(table.c.name)

        :param \*clauses: a series of :class:`_expression.ColumnElement`
         constructs
         which will be used to generate an GROUP BY clause.

        .. seealso::

            :ref:`tutorial_group_by_w_aggregates` - in the
            :ref:`unified_tutorial`

            :ref:`tutorial_order_by_label` - in the :ref:`unified_tutorial`

        r   r   NrB   c              3   d   K   | ](  }t        j                  t        j                  |       * y wr6   )r   r   r   GroupByRoler  s     r:   r   z,GenerativeSelect.group_by.<locals>.<genexpr>_  r   r  )rN  r  r   r  s     r:   r  zGenerativeSelect.group_byC  sF    2 w<1!3%'D"""e ,%, ' "r<   rb  r  )FF)%r=   r>   r?   rU   r  r  r  r  r  r  r  r1   r	  LABEL_STYLE_DEFAULTr  r   rU  r  r  r  r  rA   r  r  r  r  r  r  r  r  r  r  r  rx   r  r  r  rB   r<   r:   r  r  p  s    MNM OT
 )""H  ;
 ;
z!)V T4
D
D 
 
 
 
	
%. O O5 	
 	
 
 
 A A> / /b C C6 T./+
 0 +
Z " "H  r<   r  defaultcompound_selectc                   0    e Zd Zej                  d        Zy)CompoundSelectStatec                     | j                   j                         }d|_        t        d |j                  D              }|||fS )NFc              3   8   K   | ]  }|j                   |f  y wr6   rf  r)  s     r:   r   z:CompoundSelectState._label_resolve_dict.<locals>.<genexpr>l  s     6!%%6r,  )	statementrG   r  dictr   )r9   hacky_subqueryds      r:   _label_resolve_dictz'CompoundSelectState._label_resolve_dictg  s?     002+0(6^%5%566!Qwr<   N)r=   r>   r?   r1   r
  r  rB   r<   r:   r	  r	  e  s    	 r<   r	  c            
           e Zd ZdZdZdej                  fdej                  fdej                  fdej                  fdej                  fdej                  fd	ej                  fd
ej                  fdej                  fg	e
j                  z   Z ej                  d      Z ej                  d      Z ej                  d      Z ej                  d      Z ej                  d      Z ej                  d      ZdZd Zed        Zed        Zed        Zed        Zed        Zed        Zd Zd)dZd Z d Z!d Z"d Z# fd Z$e%d!        Z&e%d"        Z'e% ejP                  d#d$d%&      d'               Z)e)jT                  d(        Z) xZ+S )*CompoundSelectaX  Forms the basis of ``UNION``, ``UNION ALL``, and other
    SELECT-based set operations.


    .. seealso::

        :func:`_expression.union`

        :func:`_expression.union_all`

        :func:`_expression.intersect`

        :func:`_expression.intersect_all`

        :func:`_expression.except`

        :func:`_expression.except_all`

    r  selectsr  r  r  r  r  r  r  keywordUNIONz	UNION ALLEXCEPTz
EXCEPT ALL	INTERSECTzINTERSECT ALLTc                 V   |j                  dd      | _        || _        |D cg c]6  }t        j                  t
        j                  |      j                  |       8 c}| _        |r't        j                  rt        j                  dd       t        j                  | fi | y c c}w )Nr  Fr  zSet functions such as union(), union_all(), extract(), etc. in SQLAlchemy 2.0 will accept a series of SELECT statements only. Please use generative methods such as order_by() for additional modifications to this CompoundSelect.r  r  )r   _auto_correlater  r   r   r   CompoundElementRoler  r  r1   r  r  r  r  )r9   r  r  rJ   ss        r:   r  zCompoundSelect.__init__  s    %zz+u=
 	
  U66:EE F 
 d--##C
  	!!$1&1#
s   ;B&c                 <    t        t         j                  g|i |S )a  Return a ``UNION`` of multiple selectables.

        The returned object is an instance of
        :class:`_expression.CompoundSelect`.

        A similar :func:`union()` method is available on all
        :class:`_expression.FromClause` subclasses.

        :param \*selects:
          a list of :class:`_expression.Select` instances.

        :param \**kwargs:
          available keyword arguments are the same as those of
          :func:`select`.

        )r  r  r  r  rJ   s      r:   _create_unionzCompoundSelect._create_union  s    $ n22GWGGGr<   c                 <    t        t         j                  g|i |S )a  Return a ``UNION ALL`` of multiple selectables.

        The returned object is an instance of
        :class:`_expression.CompoundSelect`.

        A similar :func:`union_all()` method is available on all
        :class:`_expression.FromClause` subclasses.

        :param \*selects:
          a list of :class:`_expression.Select` instances.

        :param \**kwargs:
          available keyword arguments are the same as those of
          :func:`select`.

        )r  	UNION_ALLr  s      r:   _create_union_allz CompoundSelect._create_union_all  s    $ n66KKFKKr<   c                 <    t        t         j                  g|i |S )a]  Return an ``EXCEPT`` of multiple selectables.

        The returned object is an instance of
        :class:`_expression.CompoundSelect`.

        :param \*selects:
          a list of :class:`_expression.Select` instances.

        :param \**kwargs:
          available keyword arguments are the same as those of
          :func:`select`.

        )r  r  r  s      r:   _create_exceptzCompoundSelect._create_except  s     n33HgHHHr<   c                 <    t        t         j                  g|i |S )aa  Return an ``EXCEPT ALL`` of multiple selectables.

        The returned object is an instance of
        :class:`_expression.CompoundSelect`.

        :param \*selects:
          a list of :class:`_expression.Select` instances.

        :param \**kwargs:
          available keyword arguments are the same as those of
          :func:`select`.

        )r  
EXCEPT_ALLr  s      r:   _create_except_allz!CompoundSelect._create_except_all  s     n77L'LVLLr<   c                 <    t        t         j                  g|i |S )a`  Return an ``INTERSECT`` of multiple selectables.

        The returned object is an instance of
        :class:`_expression.CompoundSelect`.

        :param \*selects:
          a list of :class:`_expression.Select` instances.

        :param \**kwargs:
          available keyword arguments are the same as those of
          :func:`select`.

        )r  r  r  s      r:   _create_intersectz CompoundSelect._create_intersect  s     n66KKFKKr<   c                 <    t        t         j                  g|i |S )ad  Return an ``INTERSECT ALL`` of multiple selectables.

        The returned object is an instance of
        :class:`_expression.CompoundSelect`.

        :param \*selects:
          a list of :class:`_expression.Select` instances.

        :param \**kwargs:
          available keyword arguments are the same as those of
          :func:`select`.

        )r  INTERSECT_ALLr  s      r:   _create_intersect_allz$CompoundSelect._create_intersect_all  s     n::OWOOOr<   c                 <    | j                   d   j                         S Nr   )r  _scalar_typer8   s    r:   r.  zCompoundSelect._scalar_type  s    ||A++--r<   c                     t        |       S r6   )r  r&  s     r:   r  zCompoundSelect.self_group!  s    &t,,r<   c                 L    | j                   D ]  }|j                  |      s y yNTF)r  r   )r9   r   r  s      r:   r   zCompoundSelect.is_derived_from$  s+     	A  ,	 r<   c                     | j                   |urF| j                         } | j                  d   j                  |      }|g| j                  dd  z   | _        | S Nr   r   )r  r  r  _set_label_style)r9   r  select_0s      r:   r4  zCompoundSelect._set_label_style*  sR    E)>>#D||A77>H$:QR(88DLr<   c                     | j                   d   j                         }|| j                   d   ur(| j                         } |g| j                   dd  z   | _         | S r3  )r  r  r  )r9   
new_selects     r:   r  z*CompoundSelect._ensure_disambiguated_names2  sR    \\!_@@B
T\\!_,>>#D&<$,,qr*::DLr<   c           
         | j                   d   }| j                  t        ur|j                  | j                        }|j	                  |       t        |j                  j                  t        | j                   D cg c]  }|j                   c}       D ]<  \  }}t        |      D cg c]  \  }}|j                  d|dz   i       c}}|_        > y c c}w c c}}w )Nr   weightr   )r  r  r  r  r   zipr   _all_columnsrx  	enumerate	_annotate_proxies)r9   rG   r5  r  subq_colselect_colsir   s           r:   r   z2CompoundSelect._generate_fromclause_column_proxies:  s     <<?$77//0A0ABH44X> &)JJ##dll;!$$;<&
 	!Hk (4!Q Xq1u-.!H		;!s   ;C* Cc                 p    t         t        |   |       | j                  D ]  }|j                  |        y r6   )r?  r  r_   r  )r9   r^   r   r   s      r:   r_   z&CompoundSelect._refresh_for_new_columnZ  s3    nd;FCll 	3F**62	3r<   c                 4    | j                   d   j                  S r-  )r  rR   r8   s    r:   rR   z$CompoundSelect._all_selected_columns_  s    ||A444r<   c                 4    | j                   d   j                  S )a\  A :class:`_expression.ColumnCollection`
        representing the columns that
        this SELECT statement or similar construct returns in its result set,
        not including :class:`_sql.TextClause` constructs.

        For a :class:`_expression.CompoundSelect`, the
        :attr:`_expression.CompoundSelect.selected_columns`
        attribute returns the selected
        columns of the first SELECT statement contained within the series of
        statements within the set operation.

        .. seealso::

            :attr:`_sql.Select.selected_columns`

        .. versionadded:: 1.4

        r   )r  rx  r8   s    r:   rx  zCompoundSelect.selected_columnsc  s    ( ||A///r<   r  r  Fr  c                 z    | j                   r| j                   S | j                  D ]  }|j                  }|s|c S  y)Returns the :class:`_engine.Engine` or :class:`_engine.Connection`
        to which this :class:`.Executable` is bound, or None if none found.

        N)r  r  r  )r9   r  es      r:   r  zCompoundSelect.bindy  s>     :::: 	AA	
 r<   c                     || _         y r6   r  r9   r  s     r:   r  zCompoundSelect.bind  	    
r<   r6   ),r=   r>   r?   rU   ru   r.   r  r  dp_plain_dictrK  r   %_clone_annotations_traverse_internalsr  r1   symbolr  r   r  r%  r  r*  r  r  r  r  r!  r#  r&  r(  r+  r.  r  r   r4  r  r   r_   rA   rR   rx  r  r  setterr  r  s   @r:   r  r  p  s8   ( 'N 
%;;<	+<<=	,==>	+<<=	 "3"A"AB	/EEF	/EEF	->>?	%//0
 	!FF
G DKK EK(IT[["F\*JK(IDKK0M2, H H& L L& I I  M M  L L  P P .-@3
 5 5 0 0* T"K
  
[[ r<   r  c                   <   e Zd ZdZ ej
                  dd      d        Z ej
                  dd      d        Z ej
                  dd      d        Z ej
                  dd	      d
        Z	 ej
                  dd      d        Z
 ej
                  dd      d        Zy)DeprecatedSelectGenerationszA collection of methods available on :class:`_sql.Select`, these
    are all **deprecated** methods as they modify the :class:`_sql.Select`
    object in -place.

    rC   zThe :meth:`_expression.Select.append_correlation` method is deprecated and will be removed in a future release.  Use the generative method :meth:`_expression.Select.correlate`.c                 <    | j                   j                  | |       y)a  Append the given correlation expression to this select()
        construct.

        This is an **in-place** mutation method; the
        :meth:`_expression.Select.correlate` method is preferred,
        as it provides
        standard :term:`method chaining`.

        N)r  r  r   s     r:   append_correlationz.DeprecatedSelectGenerations.append_correlation  s    $ 	%%dJ7r<   zThe :meth:`_expression.Select.append_column` method is deprecated and will be removed in a future release.  Use the generative method :meth:`_expression.Select.add_columns`.c                 <    | j                   j                  | |       y)ao  Append the given column expression to the columns clause of this
        select() construct.

        E.g.::

            my_select.append_column(some_table.c.new_column)

        This is an **in-place** mutation method; the
        :meth:`_expression.Select.add_columns` method is preferred,
        as it provides standard
        :term:`method chaining`.

        N)add_columnsr  r]   s     r:   r4  z)DeprecatedSelectGenerations.append_column  s    ( 	''f5r<   zThe :meth:`_expression.Select.append_prefix` method is deprecated and will be removed in a future release.  Use the generative method :meth:`_expression.Select.prefix_with`.c                 <    | j                   j                  | |       y)a  Append the given columns clause prefix expression to this select()
        construct.

        This is an **in-place** mutation method; the
        :meth:`_expression.Select.prefix_with` method is preferred,
        as it provides
        standard :term:`method chaining`.

        N)r   r  r  s     r:   append_prefixz)DeprecatedSelectGenerations.append_prefix  s      	''f5r<   zThe :meth:`_expression.Select.append_whereclause` method is deprecated and will be removed in a future release.  Use the generative method :meth:`_expression.Select.where`.c                 <    | j                   j                  | |       y)a\  Append the given expression to this select() construct's WHERE
        criterion.

        The expression will be joined to existing WHERE criterion via AND.

        This is an **in-place** mutation method; the
        :meth:`_expression.Select.where` method is preferred,
        as it provides standard
        :term:`method chaining`.

        N)wherer  )r9   r   s     r:   append_whereclausez.DeprecatedSelectGenerations.append_whereclause  s    & 	

!!$4r<   zThe :meth:`_expression.Select.append_having` method is deprecated and will be removed in a future release.  Use the generative method :meth:`_expression.Select.having`.c                 <    | j                   j                  | |       y)a_  Append the given expression to this select() construct's HAVING
        criterion.

        The expression will be joined to existing HAVING criterion via AND.

        This is an **in-place** mutation method; the
        :meth:`_expression.Select.having` method is preferred,
        as it provides standard
        :term:`method chaining`.

        N)havingr  r9   r\  s     r:   append_havingz)DeprecatedSelectGenerations.append_having  s    & 	""40r<   zThe :meth:`_expression.Select.append_from` method is deprecated and will be removed in a future release.  Use the generative method :meth:`_expression.Select.select_from`.c                 <    | j                   j                  | |       y)a2  Append the given :class:`_expression.FromClause` expression
        to this select() construct's FROM clause.

        This is an **in-place** mutation method; the
        :meth:`_expression.Select.select_from` method is preferred,
        as it provides
        standard :term:`method chaining`.

        N)r~  r  r   s     r:   append_fromz'DeprecatedSelectGenerations.append_from  s      	''j9r<   N)r=   r>   r?   rU   r1   rw   rS  r4  rW  rZ  r^  r`  rB   r<   r:   rQ  rQ    s     T__	788 T__	966  T__	9
6
6 T__	355 T__	411 T__	9
:
:r<   rQ  r   c                   *   e Zd ZdZ G d de      Zd Zed        Zed        Z	ed        Z
ed        Zed	        Zd
 Zedd       Z	 ddZd Zed        Zed        Zd Z ej*                  d      d        Z ej*                  d      d        Zy)SelectState)from_clausesfromscolumns_plus_namesr  c                       e Zd Zg Zy)*SelectState.default_select_compile_optionsN)r=   r>   r?   _cache_key_traversalrB   r<   r:   default_select_compile_optionsrg    s    !r<   ri  c                 ^   || _         |j                  | _        |j                  D ](  }| j	                  |j                  |j
                         * |j                  r&| j	                  |j                  |j
                         | j                  |      | _        |j                  d      | _	        y r  )
r  	_from_objrc  _memoized_select_entities_setup_joins_raw_columns
_get_fromsrd  r  re  )r9   r  compilerr   memoized_entitiess        r:   r  zSelectState.__init__  s    "%//!*!D!D 	!..0A0N0N	
 !!i44i6L6LM__Y/
"+"H"H"Nr<   c                     t        d      )NzLThe default SELECT construct without plugins does not implement this method.rP   )r  s    r:   _plugin_not_implementedz#SelectState._plugin_not_implemented.  s    !%
 	
r<   c           
      ~    |j                  d      D cg c]  \  }}}}}||j                  |d c}}}S c c}}}w )NF)rf   rj  r|   )r  rj  )r  r  _rf   r  s        r:   get_column_descriptionsz#SelectState.get_column_descriptions5  sO     66u=	
 	
 '4GQ	 	
 		
 	
s   8c                 $    | j                          y r6   )rs  )r  r  from_statements      r:   rx  zSelectState.from_statementB  s    ##%r<   c                     | j                  t        j                  j                  d |j                  D                    S )Nc              3   4   K   | ]  }|j                     y wr6   r   )r   r  s     r:   r   z7SelectState.get_columns_clause_froms.<locals>.<genexpr>I  s      **1%%*rw  )_normalize_fromsr0  r1  from_iterablern  )r  r  s     r:   get_columns_clause_fromsz$SelectState.get_columns_clause_fromsF  s:    ##OO)) *5>5K5K* 
 	
r<   c                 h    |t         u |t        ut               t               dfd	}|S )Nc                 F   | j                   ry s| j                  }|d}|S r| j                  n| j                  }|-d}|v r| j                  |      z  S j	                  |       |S |v r r| j
                  z  S | j                  z  S j	                  |       |S )N	_no_label)_is_text_clause
_proxy_keyr+  _anon_labelr=  _anon_tq_key_label_anon_key_label)r   col_namerf   r|  namespatable_qualifieds      r:   goz1SelectState._column_naming_convention.<locals>.goW  s      ||<&D&51??1<<D|"5===.33IIdOK ' ((2- **R/ 		$r<   r6   )r  r  r    r   )r  r  r  r|  r  r  r  s      @@@@r:   _column_naming_conventionz%SelectState._column_naming_conventionN  s;     &)GG$44	 	< 	r<   c                 v   | j                  t        j                  t        j                  j                  |j                  D cg c]  }|j
                   c}      t        j                  j                  |j                  D cg c]  }|j
                   c}      | j                        |      S c c}w c c}w )N)check_statement)r{  r0  r1  r|  rn  r   _where_criteriarc  )r9   r  r  s      r:   ro  zSelectState._get_fromsw  s    $$OO-- (1'='=#  -- -- (1'@'@#  -- !! &! % 
 	
s   B1B6Nc           
         t               }g }|D ]y  }|j                  r#|j                  |u rt        j                  d      |j                  |j                        rN|j                  |       |j                  |j                         { |r_t        t        j                  j                  |D cg c]  }t        |j                         c}            }|r|D cg c]	  }||vs| }}|S c c}w c c}w )a0  given an iterable of things to select FROM, reduce them to what
        would actually render in the FROM clause of a SELECT.

        This does the job of checking for JOINs, tables, etc. that are in fact
        overlapping due to cloning, adaption, present in overlapping joins,
        etc.

        -select() construct refers to itself as a FROM)r   r  r  r0   InvalidRequestErrorr   r   rp  r/  r0  r1  r|  r   r  )r  iterable_of_fromsr  seenrd  itemrC  toremoves           r:   r{  zSelectState._normalize_froms  s     u% 	.D  T\\_%D--C  $$T%5%56T"D,,-	. --<ABq^AMM2BH
  %*?qQh->?? C @s   /C.	C3&C3c                 x   | j                   }| j                  j                  rC| j                  j                  }|r+|D cg c]   }|t        t        ||xs d      |      vr|" }}| j                  j                  ?|D cg c]4  }|t        t        ||xs d      | j                  j                        vr|6 }}| j                  j                  rZ|rXt        |      dkD  rJ|D cg c]  }|t        ||      vr| }}t        |      s"t        j                  d| j                  z        |S c c}w c c}w c c}w )a  Return the full list of 'from' clauses to be displayed.

        Takes into account a set of existing froms which may be
        rendered in the FROM clause of enclosing selects; this Select
        may want to leave those absent if it is automatically
        correlating.

        rB   r   zSelect statement '%r' returned no FROM clauses due to auto-correlation; specify correlate(<tables>) to control correlation manually.)
rd  r  
_correlater   _correlate_exceptr   r  rN  r0   r  )r9   explicit_correlate_fromsimplicit_correlate_fromsrd  to_correlaterC  s         r:   _get_display_fromszSelectState._get_display_froms  sl    

>>$$>>44L #
/,!#;#Ar %	 
 
 >>++7 
)(7=2 NN44	 
E 
 NN**(E
Q
 +E3KLM E  u:-- 
 #'..1  c

$s   %D- 9D2%D7c                    t        d | j                  j                  D              }t        d t        | j                        D              }|j                         }|j                         D ]  \  }}|j                  ||        |||fS )Nc              3   l   K   | ],  }|j                   r|j                  xs |j                  |f . y wr6   )_allow_label_resolve	_tq_labelr   r)  s     r:   r   zASelectState._memoized_attr__label_resolve_dict.<locals>.<genexpr>  s3      
%% [[!AEE1%
s   24c              3   P   K   | ]  }|j                   r|j                  |f   y wr6   )r  r   r)  s     r:   r   zASelectState._memoized_attr__label_resolve_dict.<locals>.<genexpr>  s)      
%% UUAJ
s   $&)r  r  rR   r   rd  copyitems
setdefault)r9   	with_cols
only_froms	only_colsr   r  s         r:   "_memoized_attr__label_resolve_dictz.SelectState._memoized_attr__label_resolve_dict  s     
^^99
 
	
  
&tzz2
 


 NN$	$**, 	-JC  e,	- *i//r<   c                 @    |j                   r|j                   d   d   S y )Nr   )rm  )r  stmts     r:   determine_last_joined_entityz(SelectState.determine_last_joined_entity  s$    $$R(++r<   c                 R    t        |j                        D cg c]  }| c}S c c}w r6   )r   rn  )r  r  r   s      r:   all_selected_columnsz SelectState.all_selected_columns  s!    ,Y-C-CDEaEEEs   	$c           	      b   |D ]  \  }}}}|d   }|d   }|| j                  ||||      \  }}	n| j                  |      }	|	I| j                  |	   }
| j                  d |	 t        |
||||      fz   | j                  |	dz   d  z   | _        | j                  t        |||||      fz   | _         y )Nr   r   r  r   )"_join_determine_implicit_left_side_join_place_explicit_left_siderc  r   )r9   rI   raw_columnsr   r   r  flagsr   r   replace_from_obj_indexleft_clauses              r:   rm  zSelectState._setup_joins  s   .2 &	*UHdEI&G=D| ;;uh*
 ,0+N+N,' &1 #//0FG %%&='=>'!$$+!%	 ''(>(B(DE
F ! %)$5$5uhdK9 %!I&	r<   ri   c           	         t         j                  j                  }d}| j                  }|r,|j	                  |||      }t        |      dk(  r|d   }||   }ni }	| j                  }
t        j                  t        j                  j                  |D cg c]  }|j                   c}      t        j                  j                  |
j                  D cg c]  }|j                   c}            D ]  }d|	|<   	 t        |	j                               }|j	                  |||      }t        |      dk(  r||d      }t        |      dkD  rt        j                  d      |st        j                  d|d      ||fS c c}w c c}w )zWhen join conditions don't express the left side explicitly,
        determine if an existing FROM or entity in this query
        can serve as the left hand side.

        Nr   r   rB   a  Can't determine which FROM clause to join from, there are multiple FROMS which can join to this entity. Please use the .select_from() method to establish an explicit left side, as well as providing an explicit ON clause if not present already to help resolve the ambiguity.zDon't know how to join to z. Please use the .select_from() method to establish an explicit left side, as well as providing an explicit ON clause if not present already to help resolve the ambiguity.)r1   rk   rl   rc  find_left_clause_to_join_fromrN  r  r0  r1  r|  r   r  rQ  keysr0   r  )r9   r  r  r   r   rl   r  rc  indexes	potentialr  r  from_clauseall_clausess                 r:   r  z.SelectState._join_determine_implicit_left_side8  s    >>**!%((<<eXG 7|q )0&#$:;II(--:EFwW**F -- (1'@'@#  --	
  , *,	+&, y~~/0K<<UHG 7|q "71:.w<!)).  ))
 27	9  +++K Gs   E=Fc                    d }t         j                  j                  }t        | j                  j                               }|r|j                  | j                  |      }ng }t        |      dkD  rt        j                  d      |r|d   }|S )Nr   zrCan't identify which entity in which to assign the left side of this join.   Please use a more specific ON clause.r   )r1   rk   rl   rQ  r  _iterate_from_elements#find_left_clause_that_matches_givenrc  rN  r0   r  )r9   r  r  rl   rc  r  s         r:   r  z*SelectState._join_place_explicit_left_side~  s    !%>>**DNNAACDBB!!4G Gw<!))  %,QZ"
 &%r<   r6   r  )r=   r>   r?   	__slots__r   ri  r  r  rs  rv  rx  r}  r  ro  r{  r  r  r  r  rm  r1   rx   r  r  rB   r<   r:   rb  rb    s%   I")9 "O  
 
 

 

 & & 
 
 & &P
( ! !H GKBH0"   F F'R T./C, 0C,J T./& 0&r<   rb  c                       e Zd Zd Zy)_SelectFromElementsc              #   f  K   t               }| j                  D ]-  }|j                  D ]  }||v r|j                  |       |  / | j                  D ]-  }|j                  D ]  }||v r|j                  |       |  / | j
                  D ]  }||v r|j                  |       |  y wr6   )r   rn  r   r=  r  rk  )r9   r  r  frs       r:   r  z*_SelectFromElements._iterate_from_elements  s      u(( 	G++ :		 ++ 	G++ :		 ~~ 	G$HHWM		s   B/B1N)r=   r>   r?   r  rB   r<   r:   r  r    s    r<   r  c                       e Zd ZdZdej
                  fdej                  fdej                  fdej                  fgZe	j                  Zd Zed        Zy)	_MemoizedSelectEntitiesmemoized_select_entitiesrn  rm  _legacy_setup_joins_with_optionsc                    | j                   j                  | j                         }| j                  j                         D ci c]  \  }}||
 c}}|_        | j                  j	                  d|       |_        |S c c}}w )N_is_clone_of)r   r  r   r  getr  )r9   r   r   kvs        r:   r   z_MemoizedSelectEntities._clone  sc    NN""4>>2'+}}':':'<=tq!ad=
**>4@ >s   A<c                 N   |j                   s|j                  s|j                  rt               }|j                  |_        |j                   |_         |j                  |_        |j                  |_        |xj
                  |fz  c_        dx|_        x|_         x|_        |_        y y r#  )rm  r  r  r  rn  rl  )r  select_stmtr9   s      r:   _generate_for_statementz/_MemoizedSelectEntities._generate_for_statement  s     $$..((*,D + 8 8D + 8 8D'2'F'FD$!,!:!:D11dW<1
 -/	/K$ /(/ /) )r<   N)r=   r>   r?   ru   r.   r  dp_setup_join_tupledp_executable_optionsr  r1   
EMPTY_DICT_annotationsr   r  r  rB   r<   r:   r  r    ss     0N 
*@@A	*>>?	 1 E EF	+AAB	 ??L / /r<   r  c                   ~    e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZdZdZej"                  Zdej(                  fdej*                  fd	ej(                  fd
ej,                  fdej,                  fdej,                  fdej,                  fdej.                  fdej.                  fdej,                  fdej,                  fdej0                  fdej0                  fdej0                  fdej2                  fdej0                  fdej4                  fdej,                  fdej6                  fgej:                  z   ej>                  z   e jB                  z   e"jF                  z   e$jJ                  z   e&jN                  z   Z(e(dejR                  fgz   Z*e+d        Z,e+ e-j\                  dd      	 	 	 	 	 	 	 	 dWd              Z/e+d        Z0e0Z1e+d         Z2e+d!        Z3d" Z4d# Z5d$ Z6d% Z7d& Z8e9d'        Z:d( Z;e<dXd)       Z=dYd*Z>e<	 dXd+       Z?dYd,Z@d- ZAe9 e-j\                  d.d/      d0               ZBe9d1        ZCe9d2        ZDd3 ZEeFf fd4	ZG fd5ZHe<d6        ZId7 ZJ e-j\                  d8d9      d:        ZK e-j                  d;      dZd<       ZMe<d=        ZNe9d>        ZOeOZPe<d?        ZQe<d@        ZRe<dA        ZSe<dB        ZTe<dC        ZUe<dD        ZVeWj                  dE        ZYeWj                  dF        ZZdG Z[d[dHZ\dI Z]dJ Z^d[dKZ_dL Z`dM ZadN ZbdO ZcdP ZddQ Zee9 e-j                  dRdSdT      dU               Zgegj                  dV        Zg xZiS )\rE   a  Represents a ``SELECT`` statement.

    The :class:`_sql.Select` object is normally constructed using the
    :func:`_sql.select` function.  See that function for details.

    .. seealso::

        :func:`_sql.select`

        :ref:`tutorial_selecting_data` - in the 2.0 tutorial

    r   rB   FNTrn  rl  rk  r  _having_criteriar  r  rm  r  r  r  r  r  r  r  r  	_distinct_distinct_onr  _compile_optionsc                 `    |s|rt        j                  |g|i |S t        j                  | S r6   )rE   rF   _create_select)r  targetentitiesr  r   s        r:   r   z%Select._create_select_from_fromclause.  s3    "..xD#DDD(((33r<   r   zThe legacy calling style of :func:`_sql.select` is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at :func:`_sql.select`.c	                 ^   | j                  |       }
||
_        |durP|du r|
j                  j                  |
       n0 |
j                  j                  |
gt	        j
                  |        |0 |
j                  j                  |
gt	        j
                  |        	 t        |      }r:|D cg c](  }t        j                  t        j                  ||
      * c}|
_        ng |
_        ||
j"                  j                  |
|       ||
j$                  j                  |
|       |r|
j'                  |       |r|
j)                  |       t+        j,                  |
fi |	 |
S # t        $ r6}t	        j                  t        j                  dd      |       Y d}~d}~ww xY wc c}w )	a  Construct a new :class:`_expression.Select` using the 1.x style API.

        This method is called implicitly when the :func:`_expression.select`
        construct is used and the first argument is a Python list or other
        plain sequence object, which is taken to refer to the columns
        collection.

        .. versionchanged:: 1.4 Added the :meth:`.Select.create_legacy_select`
           constructor which documents the calling style in use when the
           :func:`.select` construct is invoked using 1.x-style arguments.

        Similar functionality is also available via the
        :meth:`_expression.FromClause.select` method on any
        :class:`_expression.FromClause`.

        All arguments which accept :class:`_expression.ClauseElement` arguments
        also accept string arguments, which will be converted as appropriate
        into either :func:`_expression.text()` or
        :func:`_expression.literal_column()` constructs.

        .. seealso::

            :ref:`tutorial_selecting_data` - in the :ref:`unified_tutorial`

        :param columns:
          A list of :class:`_expression.ColumnElement` or
          :class:`_expression.FromClause`
          objects which will form the columns clause of the resulting
          statement.   For those objects that are instances of
          :class:`_expression.FromClause` (typically :class:`_schema.Table`
          or :class:`_expression.Alias`
          objects), the :attr:`_expression.FromClause.c`
          collection is extracted
          to form a collection of :class:`_expression.ColumnElement` objects.

          This parameter will also accept :class:`_expression.TextClause`
          constructs as
          given, as well as ORM-mapped classes.

          .. note::

            The :paramref:`_expression.select.columns`
            parameter is not available
            in the method form of :func:`_expression.select`, e.g.
            :meth:`_expression.FromClause.select`.

          .. seealso::

            :meth:`_expression.Select.column`

            :meth:`_expression.Select.with_only_columns`

        :param whereclause:
          A :class:`_expression.ClauseElement`
          expression which will be used to form the
          ``WHERE`` clause.   It is typically preferable to add WHERE
          criterion to an existing :class:`_expression.Select`
          using method chaining
          with :meth:`_expression.Select.where`.

          .. seealso::

            :meth:`_expression.Select.where`

        :param from_obj:
          A list of :class:`_expression.ClauseElement`
          objects which will be added to the
          ``FROM`` clause of the resulting statement.  This is equivalent
          to calling :meth:`_expression.Select.select_from`
          using method chaining on
          an existing :class:`_expression.Select` object.

          .. seealso::

            :meth:`_expression.Select.select_from`
            - full description of explicit
            FROM clause specification.

        :param bind=None:
          an :class:`_engine.Engine` or :class:`_engine.Connection` instance
          to which the
          resulting :class:`_expression.Select` object will be bound.  The
          :class:`_expression.Select`
          object will otherwise automatically bind to
          whatever :class:`~.base.Connectable` instances can be located within
          its contained :class:`_expression.ClauseElement` members.

        :param correlate=True:
          indicates that this :class:`_expression.Select`
          object should have its
          contained :class:`_expression.FromClause`
          elements "correlated" to an enclosing
          :class:`_expression.Select` object.
          It is typically preferable to specify
          correlations on an existing :class:`_expression.Select`
          construct using
          :meth:`_expression.Select.correlate`.

          .. seealso::

            :meth:`_expression.Select.correlate`
            - full description of correlation.

        :param distinct=False:
          when ``True``, applies a ``DISTINCT`` qualifier to the columns
          clause of the resulting statement.

          The boolean argument may also be a column expression or list
          of column expressions - this is a special calling form which
          is understood by the PostgreSQL dialect to render the
          ``DISTINCT ON (<columns>)`` syntax.

          ``distinct`` is also available on an existing
          :class:`_expression.Select`
          object via the :meth:`_expression.Select.distinct` method.

          .. seealso::

            :meth:`_expression.Select.distinct`

        :param group_by:
          a list of :class:`_expression.ClauseElement`
          objects which will comprise the
          ``GROUP BY`` clause of the resulting select.  This parameter
          is typically specified more naturally using the
          :meth:`_expression.Select.group_by` method on an existing
          :class:`_expression.Select`.

          .. seealso::

            :meth:`_expression.Select.group_by`

        :param having:
          a :class:`_expression.ClauseElement`
          that will comprise the ``HAVING`` clause
          of the resulting select when ``GROUP BY`` is used.  This parameter
          is typically specified more naturally using the
          :meth:`_expression.Select.having` method on an existing
          :class:`_expression.Select`.

          .. seealso::

            :meth:`_expression.Select.having`

        :param limit=None:
          a numerical value which usually renders as a ``LIMIT``
          expression in the resulting select.  Backends that don't
          support ``LIMIT`` will attempt to provide similar
          functionality.    This parameter is typically specified more
          naturally using the :meth:`_expression.Select.limit`
          method on an existing
          :class:`_expression.Select`.

          .. seealso::

            :meth:`_expression.Select.limit`

        :param offset=None:
          a numeric value which usually renders as an ``OFFSET``
          expression in the resulting select.  Backends that don't
          support ``OFFSET`` will attempt to provide similar
          functionality.  This parameter is typically specified more naturally
          using the :meth:`_expression.Select.offset` method on an existing
          :class:`_expression.Select`.

          .. seealso::

            :meth:`_expression.Select.offset`

        :param order_by:
          a scalar or list of :class:`_expression.ClauseElement`
          objects which will
          comprise the ``ORDER BY`` clause of the resulting select.
          This parameter is typically specified more naturally using the
          :meth:`_expression.Select.order_by` method on an existing
          :class:`_expression.Select`.

          .. seealso::

            :meth:`_expression.Select.order_by`

        :param use_labels=False:
          when ``True``, the statement will be generated using labels
          for each column in the columns clause, which qualify each
          column with its parent table's (or aliases) name so that name
          conflicts between columns in different tables don't occur.
          The format of the label is ``<tablename>_<column>``.  The "c"
          collection of a :class:`_expression.Subquery` created
          against this :class:`_expression.Select`
          object, as well as the :attr:`_expression.Select.selected_columns`
          collection of the :class:`_expression.Select` itself, will use these
          names for targeting column members.

          This parameter can also be specified on an existing
          :class:`_expression.Select` object using the
          :meth:`_expression.Select.set_label_style`
          method.

          .. seealso::

            :meth:`_expression.Select.set_label_style`

        FTNzselect() construct created in legacy mode, i.e. with keyword arguments, must provide the columns argument as a Python list or other iterable.c9ae)code)from_r  )r  r  distinctr  r1   r_  r~  r\  	TypeErrorr  r0   r   r   r   r   r`  rn  rY  r\  r   r   r  r  )r  r   r   from_objr  r\  r  r   r   rJ   r9   cols_presentr  r   s                 r:   rF   zSelect.create_legacy_select5  s   | {{3(5 4,,T2,,,TKDLL4JK+D++DJ4<<3IJ	=L 
 !	!    ++Qd!D !#D"JJ%%dK8KK&&tV4  *  *!!$1&1E  		KK!!7  	  		!s    E( 1-F*(	F'1,F""F'c                     | j                  |       }|D cg c](  }t        j                  t        j                  ||      * c}|_        t        j                  |       |S c c}w )a  Construct a new :class:`_expression.Select` using the 2.
        x style API.

        .. versionadded:: 1.4 - The :func:`_sql.select` function now accepts
           column arguments positionally.   The top-level :func:`_sql.select`
           function will automatically use the 1.x or 2.x style API based on
           the incoming arguments; using :func:`_future.select` from the
           ``sqlalchemy.future`` module will enforce that only the 2.x style
           constructor is used.

        Similar functionality is also available via the
        :meth:`_expression.FromClause.select` method on any
        :class:`_expression.FromClause`.

        .. seealso::

            :ref:`coretutorial_selecting` - Core Tutorial description of
            :func:`_expression.select`.

        :param \*entities:
          Entities to SELECT from.  For Core usage, this is typically a series
          of :class:`_expression.ColumnElement` and / or
          :class:`_expression.FromClause`
          objects which will form the columns clause of the resulting
          statement.   For those objects that are instances of
          :class:`_expression.FromClause` (typically :class:`_schema.Table`
          or :class:`_expression.Alias`
          objects), the :attr:`_expression.FromClause.c`
          collection is extracted
          to form a collection of :class:`_expression.ColumnElement` objects.

          This parameter will also accept :class:`_expression.TextClause`
          constructs as
          given, as well as ORM-mapped classes.

        r  )r  r   r   r   r`  rn  r  r  )r  r  r9   ents       r:   _create_future_selectzSelect._create_future_selectF  sd    N {{3
  	
  ''D
 	!!$'
s   -A"c                 n    t         j                  t               }|j                  j                  |       |S )zCreate a :class:`.Select` using raw ``__new__`` with no coercions.

        Used internally to build up :class:`.Select` constructs with
        pre-established state.

        )rE   r  r   r/  )r  r   r  s      r:   _create_raw_selectzSelect._create_raw_select{  s)     ~~f%R r<   c                    |rft        |d   t              sUt        |d   d      rDt        |d   t        j                  t
        fz         st        |d   d      t        |d   d      r|r | j                  |i |S  | j                  | S )a  Create a :class:`.Select` using either the 1.x or 2.0 constructor
        style.

        For the legacy calling style, see :meth:`.Select.create_legacy_select`.
        If the first argument passed is a Python sequence or if keyword
        arguments are present, this style is used.

        .. versionadded:: 2.0 - the :func:`_future.select` construct is
           the same construct as the one returned by
           :func:`_expression.select`, except that the function only
           accepts the "columns clause" entities up front; the rest of the
           state of the SELECT should be built up using generative methods.

        Similar functionality is also available via the
        :meth:`_expression.FromClause.select` method on any
        :class:`_expression.FromClause`.

        .. seealso::

            :ref:`coretutorial_selecting` - Core Tutorial description of
            :func:`_expression.select`.

        :param \*entities:
          Entities to SELECT from.  For Core usage, this is typically a series
          of :class:`_expression.ColumnElement` and / or
          :class:`_expression.FromClause`
          objects which will form the columns clause of the resulting
          statement.   For those objects that are instances of
          :class:`_expression.FromClause` (typically :class:`_schema.Table`
          or :class:`_expression.Alias`
          objects), the :attr:`_expression.FromClause.c`
          collection is extracted
          to form a collection of :class:`_expression.ColumnElement` objects.

          This parameter will also accept :class:`_expression.TextClause`
          constructs as given, as well as ORM-mapped classes.

        r   __iter__F)raiseerr__clause_element__)	r6  rQ  hasattrr1   string_typesr&   r2   rF   r  )r  rI   r   s      r:   _createzSelect._create  s    R 47D)DGZ0&Q!2!2m5E!E  Q%8@#DG-AB +3++T8R88,3,,d33r<   c                     t               r6   rP   r8   s    r:   r  zSelect.__init__  r`   r<   c                 h    | j                   d   }t        |j                        }|d   j                  S r-  )rn  rQ  r  rj  )r9   ra  colss      r:   r.  zSelect._scalar_type  s0      #D))*Aw||r<   c                       | j                   | S )z6A synonym for the :meth:`_future.Select.where` method.rY  )r9   criterias     r:   filterzSelect.filter  s     tzz8$$r<   c                     | j                   r+t        j                  |       j                  } ||       }||S | j                  r| j                  d   S | j
                  d   S r-  )rm  rb  get_plugin_classr  rk  rn  )r9   meth_last_joined_entitys      r:   _filter_by_zerozSelect._filter_by_zero  sf    //**  #'t*".**>>>>!$$  ##r<   c                     | j                         }|j                         D cg c]  \  }}t        ||      |k(   }}} | j                  | S c c}}w )zWapply the given filtering criterion as a WHERE clause
        to this select.

        )r  r  r   r  )r9   rJ   from_entityr   r  r  s         r:   	filter_byzSelect.filter_by  s_    
 **, %lln
U "+s3u<
 
 t{{G$$	
s   Ac                 P    t         j                  |       j                  } ||       S )a5  Return a :term:`plugin-enabled` 'column descriptions' structure
        referring to the columns which are SELECTed by this statement.

        This attribute is generally useful when using the ORM, as an
        extended structure which includes information about mapped
        entities is returned.  The section :ref:`queryguide_inspection`
        contains more background.

        For a Core-only statement, the structure returned by this accessor
        is derived from the same objects that are returned by the
        :attr:`.Select.selected_columns` accessor, formatted as a list of
        dictionaries which contain the keys ``name``, ``type`` and ``expr``,
        which indicate the column expressions to be selected::

            >>> stmt = select(user_table)
            >>> stmt.column_descriptions
            [
                {
                    'name': 'id',
                    'type': Integer(),
                    'expr': Column('id', Integer(), ...)},
                {
                    'name': 'name',
                    'type': String(length=30),
                    'expr': Column('name', String(length=30), ...)}
            ]

        .. versionchanged:: 1.4.33 The :attr:`.Select.column_descriptions`
           attribute returns a structure for a Core-only set of entities,
           not just ORM-only entities.

        .. seealso::

            :attr:`.UpdateBase.entity_description` - entity information for
            an :func:`.insert`, :func:`.update`, or :func:`.delete`

            :ref:`queryguide_inspection` - ORM background

        )rb  r  rv  r9   r  s     r:   column_descriptionszSelect.column_descriptions  s%    R ++D1IIDzr<   c                 R    t         j                  |       j                  } || |      S )a  Apply the columns which this :class:`.Select` would select
        onto another statement.

        This operation is :term:`plugin-specific` and will raise a not
        supported exception if this :class:`_sql.Select` does not select from
        plugin-enabled entities.


        The statement is typically either a :func:`_expression.text` or
        :func:`_expression.select` construct, and should return the set of
        columns appropriate to the entities represented by this
        :class:`.Select`.

        .. seealso::

            :ref:`orm_queryguide_selecting_text` - usage examples in the
            ORM Querying Guide

        )rb  r  rx  )r9   r  r  s      r:   rx  zSelect.from_statement  s'    ( ++D1@@D)$$r<   c                     t        j                  t        j                  ||       }|$t        j                  t        j                  |      }| xj
                  ||d||dffz  c_        y)ah	  Create a SQL JOIN against this :class:`_expression.Select`
        object's criterion
        and apply generatively, returning the newly resulting
        :class:`_expression.Select`.

        E.g.::

            stmt = select(user_table).join(address_table, user_table.c.id == address_table.c.user_id)

        The above statement generates SQL similar to::

            SELECT user.id, user.name FROM user JOIN address ON user.id = address.user_id

        .. versionchanged:: 1.4 :meth:`_expression.Select.join` now creates
           a :class:`_sql.Join` object between a :class:`_sql.FromClause`
           source that is within the FROM clause of the existing SELECT,
           and a given target :class:`_sql.FromClause`, and then adds
           this :class:`_sql.Join` to the FROM clause of the newly generated
           SELECT statement.    This is completely reworked from the behavior
           in 1.3, which would instead create a subquery of the entire
           :class:`_expression.Select` and then join that subquery to the
           target.

           This is a **backwards incompatible change** as the previous behavior
           was mostly useless, producing an unnamed subquery rejected by
           most databases in any case.   The new behavior is modeled after
           that of the very successful :meth:`_orm.Query.join` method in the
           ORM, in order to support the functionality of :class:`_orm.Query`
           being available by using a :class:`_sql.Select` object with an
           :class:`_orm.Session`.

           See the notes for this change at :ref:`change_select_join`.


        :param target: target table to join towards

        :param onclause: ON clause of the join.  If omitted, an ON clause
         is generated automatically based on the :class:`_schema.ForeignKey`
         linkages between the two tables, if one can be unambiguously
         determined, otherwise an error is raised.

        :param isouter: if True, generate LEFT OUTER join.  Same as
         :meth:`_expression.Select.outerjoin`.

        :param full: if True, generate FULL OUTER join.

        .. seealso::

            :ref:`tutorial_select_join` - in the :doc:`/tutorial/index`

            :ref:`orm_queryguide_joins` - in the :ref:`queryguide_toplevel`

            :meth:`_expression.Select.join_from`

            :meth:`_expression.Select.outerjoin`

        r  Nr  )r   r   r   JoinTargetRoler  rm  )r9   r  r   r   r   s        r:   r   zSelect.join-  si    v !!  &
  ''(:(:HEHXt$%GH
 	
r<   c                 .    | j                  |||d|      S )a  Create a SQL LEFT OUTER JOIN against this
        :class:`_expression.Select` object's criterion and apply generatively,
        returning the newly resulting :class:`_expression.Select`.

        Usage is the same as that of :meth:`_selectable.Select.join_from`.

        Tr   r   r   )	join_from)r9   r  r  r   r   s        r:   outerjoin_fromzSelect.outerjoin_fromq  s%     ~~6Hd  
 	
r<   c                 "   t        j                  t        j                  ||       }t        j                  t        j                  ||       }|$t        j                  t        j
                  |      }| xj                  |||||dffz  c_        y)a  Create a SQL JOIN against this :class:`_expression.Select`
        object's criterion
        and apply generatively, returning the newly resulting
        :class:`_expression.Select`.

        E.g.::

            stmt = select(user_table, address_table).join_from(
                user_table, address_table, user_table.c.id == address_table.c.user_id
            )

        The above statement generates SQL similar to::

            SELECT user.id, user.name, address.id, address.email, address.user_id
            FROM user JOIN address ON user.id = address.user_id

        .. versionadded:: 1.4

        :param from\_: the left side of the join, will be rendered in the
         FROM clause and is roughly equivalent to using the
         :meth:`.Select.select_from` method.

        :param target: target table to join towards

        :param onclause: ON clause of the join.

        :param isouter: if True, generate LEFT OUTER join.  Same as
         :meth:`_expression.Select.outerjoin`.

        :param full: if True, generate FULL OUTER join.

        .. seealso::

            :ref:`tutorial_select_join` - in the :doc:`/tutorial/index`

            :ref:`orm_queryguide_joins` - in the :ref:`queryguide_toplevel`

            :meth:`_expression.Select.join`

        r  Nr  )r   r   r   r   r  r  rm  )r9   r  r  r   r   r   s         r:   r
  zSelect.join_from}  s    b     %t
 !!  &
  ''(:(:HEHXu'4&HI
 	
r<   c                 ,    | j                  ||d|      S )a  Create a left outer join.

        Parameters are the same as that of :meth:`_expression.Select.join`.

        .. versionchanged:: 1.4 :meth:`_expression.Select.outerjoin` now
           creates a :class:`_sql.Join` object between a
           :class:`_sql.FromClause` source that is within the FROM clause of
           the existing SELECT, and a given target :class:`_sql.FromClause`,
           and then adds this :class:`_sql.Join` to the FROM clause of the
           newly generated SELECT statement.    This is completely reworked
           from the behavior in 1.3, which would instead create a subquery of
           the entire
           :class:`_expression.Select` and then join that subquery to the
           target.

           This is a **backwards incompatible change** as the previous behavior
           was mostly useless, producing an unnamed subquery rejected by
           most databases in any case.   The new behavior is modeled after
           that of the very successful :meth:`_orm.Query.join` method in the
           ORM, in order to support the functionality of :class:`_orm.Query`
           being available by using a :class:`_sql.Select` object with an
           :class:`_orm.Session`.

           See the notes for this change at :ref:`change_select_join`.

        .. seealso::

            :ref:`tutorial_select_join` - in the :doc:`/tutorial/index`

            :ref:`orm_queryguide_joins` - in the :ref:`queryguide_toplevel`

            :meth:`_expression.Select.join`

        Tr	  )r   )r9   r  r   r   s       r:   r   zSelect.outerjoin  s    F yy(DtyLLr<   c                 B    | j                  | d      j                         S )aG  Compute the final displayed list of :class:`_expression.FromClause`
        elements.

        This method will run through the full computation required to
        determine what FROM elements will be displayed in the resulting
        SELECT statement, including shadowing individual tables with
        JOIN objects, as well as full computation for ORM use cases including
        eager loading clauses.

        For ORM use, this accessor returns the **post compilation**
        list of FROM objects; this collection will include elements such as
        eagerly loaded tables and joins.  The objects will **not** be
        ORM enabled and not work as a replacement for the
        :meth:`_sql.Select.select_froms` collection; additionally, the
        method is not well performing for an ORM enabled statement as it
        will incur the full ORM construction process.

        To retrieve the FROM list that's implied by the "columns" collection
        passed to the :class:`_sql.Select` originally, use the
        :attr:`_sql.Select.columns_clause_froms` accessor.

        To select from an alternative set of columns while maintaining the
        FROM list, use the :meth:`_sql.Select.with_only_columns` method and
        pass the
        :paramref:`_sql.Select.with_only_columns.maintain_column_froms`
        parameter.

        .. versionadded:: 1.4.23 - the :meth:`_sql.Select.get_final_froms`
           method replaces the previous :attr:`_sql.Select.froms` accessor,
           which is deprecated.

        .. seealso::

            :attr:`_sql.Select.columns_clause_froms`

        N)_compile_state_factoryr  r8   s    r:   get_final_fromszSelect.get_final_froms  s!    J **46IIKKr<   z1.4.23zqThe :attr:`_expression.Select.froms` attribute is moved to the :meth:`_expression.Select.get_final_froms` method.c                 "    | j                         S )zYReturn the displayed list of :class:`_expression.FromClause`
        elements.


        )r  r8   s    r:   rd  zSelect.froms  s     ##%%r<   c                 J    t         j                  |       j                  |       S )a  Return the set of :class:`_expression.FromClause` objects implied
        by the columns clause of this SELECT statement.

        .. versionadded:: 1.4.23

        .. seealso::

            :attr:`_sql.Select.froms` - "final" FROM list taking the full
            statement into account

            :meth:`_sql.Select.with_only_columns` - makes use of this
            collection to set up a new FROM list

        )rb  r  r}  r8   s    r:   columns_clause_fromszSelect.columns_clause_froms  s%    " ++D1JJ
 	
r<   c                 ,    t        | j                        S )a0  An iterator of all :class:`_expression.ColumnElement`
        expressions which would
        be rendered into the columns clause of the resulting SELECT statement.

        This method is legacy as of 1.4 and is superseded by the
        :attr:`_expression.Select.exported_columns` collection.

        )iterrR   r8   s    r:   inner_columnszSelect.inner_columns*  s     D..//r<   c                 r    | |j                   v ry| j                         D ]  }|j                  |      s y yr1  )r   r  r   )r9   r   rC  s      r:   r   zSelect.is_derived_from7  sA    :))),,. 	A  ,	 r<   c                 l  	 t        t        j                  t        | j                   t        | j
                   t        | j                  D cg c]  }|d   	 c}             }|D ci c]  }| ||fi | c}	| j                  D cg c]  } ||fi | }}t        d 	j                         D              j                  |      j                  |      }t        |      t        |      z   | _        	fd}||d<   t        t        | 6  d|dd| | j                          y c c}w c c}w c c}w )Nr   c              3   B   K   | ]  }t        |t              s|  y wr6   )r6  r   rv  s     r:   r   z)Select._copy_internals.<locals>.<genexpr>\  s     EaAt1DEs   c                     t        | t              r/| j                  v r | j                     j                  |       }|S y y r6   r5  r8  s      r:   r<  z'Select._copy_internals.<locals>.replacee  r=  r<   r<  )rk  )r>  
omit_attrsrB   )r   r0  r1  r   rn  r  rm  rk  rR  
differencer   r?  rE   r@  rA  )r9   r>  r   ra  rB  rC  existing_from_obj	add_fromsr<  r;  r   s            @r:   r@  zSelect._copy_internals@  s2    OOt001t334D4E4EFDQFG
 1>>1Qa2&>	 6:^^DU1^^DDE9++-EEZ&Z)* 	 01E)4DD	
  9 	fd+ 	
N	
68	
 	  "O  G ? Es   D'(D,
D1c                 t    t        j                  t        t        |   g d      | j                               S )N)rk  r  r  )r  )r0  r1  r?  rE   get_childrenr  )r9   rJ   r   s     r:   r   zSelect.get_childrenv  s9    &$,K -  '')	
 	
r<   c           	          | j                          | j                  |D cg c](  }t        j                  t        j
                  ||       * c}z   | _        yc c}w )a  Return a new :func:`_expression.select` construct with
        the given column expressions added to its columns clause.

        E.g.::

            my_select = my_select.add_columns(table.c.new_column)

        See the documentation for
        :meth:`_expression.Select.with_only_columns`
        for guidelines on adding /replacing the columns of a
        :class:`_expression.Select` object.

        r  N)rA  rn  r   r   r   r`  )r9   r   r^   s      r:   rU  zSelect.add_columns~  sZ     	  " -- "	1
  ''t1
 
 1
s   -Ac                     t        j                  |      D cg c](  }t        j                  t        j
                  ||       * c}| _        y c c}w )Nr  )r1   r_  r   r   r   r`  rn  )r9   r  r  s      r:   _set_entitieszSelect._set_entities  sG    
 ||H-	
  ''D
 
s   -ArC   zThe :meth:`_expression.Select.column` method is deprecated and will be removed in a future release.  Please use :meth:`_expression.Select.add_columns`c                 $    | j                  |      S )a  Return a new :func:`_expression.select` construct with
        the given column expression added to its columns clause.

        E.g.::

            my_select = my_select.column(table.c.new_column)

        See the documentation for
        :meth:`_expression.Select.with_only_columns`
        for guidelines on adding /replacing the columns of a
        :class:`_expression.Select` object.

        )rU  r]   s     r:   r^   zSelect.column  s    ( ''r<   ri   c                      | j                   t        j                  j                  j                  | j
                  g| j                  | j                  z   d|i S )a"  Return a new :func:`_expression.select` construct with redundantly
        named, equivalently-valued columns removed from the columns clause.

        "Redundant" here means two columns where one refers to the
        other either based on foreign key, or via a simple equality
        comparison in the WHERE clause of the statement.   The primary purpose
        of this method is to automatically construct a select statement
        with all uniquely-named columns, without the need to use
        table-qualified labels as
        :meth:`_expression.Select.set_label_style`
        does.

        When columns are omitted based on foreign key, the referred-to
        column is the one that's kept.  When columns are omitted based on
        WHERE equivalence, the first column in the columns clause is the
        one that's kept.

        :param only_synonyms: when True, limit the removal of columns
         to those which have the same name as the equivalent.   Otherwise,
         all columns that are equivalent to another are removed.

        only_synonyms)with_only_columnsr1   rk   rl   r.  rR   r  rk  )r9   r&  s     r:   r.  zSelect.reduce_columns  s[    0 &t%%^^$$33** &&7+
 	
r<   c                    | j                          |j                  dd      }|rt        ddj                  |            |r' | j                  j
                  | g| j                    t        j                  |        t        j                  dd|      D cg c]&  }t        j                  t        j                  |      ( c}| _        yc c}w )a  Return a new :func:`_expression.select` construct with its columns
        clause replaced with the given columns.

        By default, this method is exactly equivalent to as if the original
        :func:`_expression.select` had been called with the given columns
        clause. E.g. a statement::

            s = select(table1.c.a, table1.c.b)
            s = s.with_only_columns(table1.c.b)

        should be exactly equivalent to::

            s = select(table1.c.b)

        In this mode of operation, :meth:`_sql.Select.with_only_columns`
        will also dynamically alter the FROM clause of the
        statement if it is not explicitly stated.
        To maintain the existing set of FROMs including those implied by the
        current columns clause, add the
        :paramref:`_sql.Select.with_only_columns.maintain_column_froms`
        parameter::

            s = select(table1.c.a, table2.c.b)
            s = s.with_only_columns(table1.c.a, maintain_column_froms=True)

        The above parameter performs a transfer of the effective FROMs
        in the columns collection to the :meth:`_sql.Select.select_from`
        method, as though the following were invoked::

            s = select(table1.c.a, table2.c.b)
            s = s.select_from(table1, table2).with_only_columns(table1.c.a)

        The :paramref:`_sql.Select.with_only_columns.maintain_column_froms`
        parameter makes use of the :attr:`_sql.Select.columns_clause_froms`
        collection and performs an operation equivalent to the following::

            s = select(table1.c.a, table2.c.b)
            s = s.select_from(*s.columns_clause_froms).with_only_columns(table1.c.a)

        :param \*columns: column expressions to be used.

         .. versionchanged:: 1.4 the :meth:`_sql.Select.with_only_columns`
            method accepts the list of column expressions positionally;
            passing the expressions as a list is deprecated.

        :param maintain_column_froms: boolean parameter that will ensure the
         FROM list implied from the current columns clause will be transferred
         to the :meth:`_sql.Select.select_from` method first.

         .. versionadded:: 1.4.23

        maintain_column_fromsFzunknown parameters: z, r   zSelect.with_only_columnsN)_assert_no_memoizationsr   r  r   r~  r  r  r  r  r   !_expression_collection_was_a_listr   r   r`  rn  )r9   r   r   r)  r   s        r:   r'  zSelect.with_only_columns  s    t 	$$& "'> F		"GHH +D++DM43L3LM 	 77= @@5w
 U44a8
 
s   +Cc                 @    t        j                  | j                        S )a  Return the completed WHERE clause for this
        :class:`_expression.Select` statement.

        This assembles the current collection of WHERE criteria
        into a single :class:`_expression.BooleanClauseList` construct.


        .. versionadded:: 1.4

        )r%   _construct_for_whereclauser  r8   s    r:   r   zSelect.whereclause!  s      !;;  
 	
r<   c                     t        | j                  t              sJ |D ]<  }t        j                  t
        j                  |      }| xj                  |fz  c_        > y)zReturn a new :func:`_expression.select` construct with
        the given expression added to
        its WHERE clause, joined to the existing clause via AND, if any.

        N)r6  r  r   r   r   r   WhereHavingRole)r9   r   	criterionwhere_criterias       r:   rY  zSelect.where4  sU     $..666$ 	6I&--e.C.CYON  ^$55 	6r<   c                 t    | xj                   t        j                  t        j                  |      fz  c_         y)zReturn a new :func:`_expression.select` construct with
        the given expression added to
        its HAVING clause, joined to the existing clause via AND, if any.

        N)r  r   r   r   r/  r]  s     r:   r\  zSelect.havingB  s0     	U22F;"
 	
r<   c                 n    |r,d| _         | j                  t        d |D              z   | _        yd| _         y)a  Return a new :func:`_expression.select` construct which
        will apply DISTINCT to its columns clause.

        :param \*expr: optional column expressions.  When present,
         the PostgreSQL dialect will render a ``DISTINCT ON (<expressions>>)``
         construct.

         .. deprecated:: 1.4 Using \*expr in other dialects is deprecated
            and will raise :class:`_exc.CompileError` in a future version.

        Tc              3   d   K   | ](  }t        j                  t        j                  |       * y wr6   )r   r   r   ByOfRole)r   rG  s     r:   r   z"Select.distinct.<locals>.<genexpr>\  s&      :89	  3:r  N)r  r  r   )r9   r|   s     r:   r  zSelect.distinctM  s>     !DN $ 1 1E :=A: 5 !D "DNr<   c                 T      xj                   t         fd|D              z  c_         y)a  Return a new :func:`_expression.select` construct with the
        given FROM expression(s)
        merged into its list of FROM objects.

        E.g.::

            table1 = table('t1', column('a'))
            table2 = table('t2', column('b'))
            s = select(table1.c.a).\
                select_from(
                    table1.join(table2, table1.c.a==table2.c.b)
                )

        The "from" list is a unique set on the identity of each element,
        so adding an already present :class:`_schema.Table`
        or other selectable
        will have no effect.   Passing a :class:`_expression.Join` that refers
        to an already present :class:`_schema.Table`
        or other selectable will have
        the effect of concealing the presence of that selectable as
        an individual element in the rendered FROM list, instead
        rendering it into a JOIN clause.

        While the typical purpose of :meth:`_expression.Select.select_from`
        is to
        replace the default, derived FROM clause with a join, it can
        also be called with individual table elements, multiple times
        if desired, in the case that the FROM clause cannot be fully
        derived from the columns clause::

            select(func.count('*')).select_from(table1)

        c              3   j   K   | ]*  }t        j                  t        j                  |        , yw)r  Nr   r   r   r   )r   r   r9   s     r:   r   z%Select.select_from.<locals>.<genexpr>  s8       
  $$j  
s   03N)rk  r   )r9   rd  s   ` r:   r~  zSelect.select_fromb  s*    H 	%  
 $	 
 
 	
r<   c                 |    d| _         |r|d   dv rd| _        y| j                  t        d |D              z   | _        y)aX  Return a new :class:`_expression.Select`
        which will correlate the given FROM
        clauses to that of an enclosing :class:`_expression.Select`.

        Calling this method turns off the :class:`_expression.Select` object's
        default behavior of "auto-correlation".  Normally, FROM elements
        which appear in a :class:`_expression.Select`
        that encloses this one via
        its :term:`WHERE clause`, ORDER BY, HAVING or
        :term:`columns clause` will be omitted from this
        :class:`_expression.Select`
        object's :term:`FROM clause`.
        Setting an explicit correlation collection using the
        :meth:`_expression.Select.correlate`
        method provides a fixed list of FROM objects
        that can potentially take place in this process.

        When :meth:`_expression.Select.correlate`
        is used to apply specific FROM clauses
        for correlation, the FROM elements become candidates for
        correlation regardless of how deeply nested this
        :class:`_expression.Select`
        object is, relative to an enclosing :class:`_expression.Select`
        which refers to
        the same FROM object.  This is in contrast to the behavior of
        "auto-correlation" which only correlates to an immediate enclosing
        :class:`_expression.Select`.
        Multi-level correlation ensures that the link
        between enclosed and enclosing :class:`_expression.Select`
        is always via
        at least one WHERE/ORDER BY/HAVING/columns clause in order for
        correlation to take place.

        If ``None`` is passed, the :class:`_expression.Select`
        object will correlate
        none of its FROM entries, and all will render unconditionally
        in the local FROM clause.

        :param \*fromclauses: a list of one or more
         :class:`_expression.FromClause`
         constructs, or other compatible constructs (i.e. ORM-mapped
         classes) to become part of the correlate collection.

        .. seealso::

            :meth:`_expression.Select.correlate_except`

            :ref:`tutorial_scalar_subquery`

        Fr      FNrB   c              3   d   K   | ](  }t        j                  t        j                  |       * y wr6   r8  rv  s     r:   r   z#Select.correlate.<locals>.<genexpr>  s(      6>?	  !5!5q96r  N)r  r  r   r9   fromclausess     r:   r  zSelect.correlate  sF    j  %;q>]: DO"oo 6CN6 1 DOr<   c                     d| _         |r|d   dv rd| _        y| j                  xs dt        d |D              z   | _        y)a  Return a new :class:`_expression.Select`
        which will omit the given FROM
        clauses from the auto-correlation process.

        Calling :meth:`_expression.Select.correlate_except` turns off the
        :class:`_expression.Select` object's default behavior of
        "auto-correlation" for the given FROM elements.  An element
        specified here will unconditionally appear in the FROM list, while
        all other FROM elements remain subject to normal auto-correlation
        behaviors.

        If ``None`` is passed, the :class:`_expression.Select`
        object will correlate
        all of its FROM entries.

        :param \*fromclauses: a list of one or more
         :class:`_expression.FromClause`
         constructs, or other compatible constructs (i.e. ORM-mapped
         classes) to become part of the correlate-exception collection.

        .. seealso::

            :meth:`_expression.Select.correlate`

            :ref:`tutorial_scalar_subquery`

        Fr   r:  rB   c              3   d   K   | ](  }t        j                  t        j                  |       * y wr6   r8  rv  s     r:   r   z*Select.correlate_except.<locals>.<genexpr>  s*      L>?	  !5!5q9Lr  N)r  r  r   r<  s     r:   correlate_exceptzSelect.correlate_except  sQ    <  %;q>]:%'D"&*&<&<&Be LCNL G &D"r<   c                     t         j                  | j                        }t        | j                  D cg c]  }|j
                  s
 ||      |f c}      j                         S c c}w )a-  A :class:`_expression.ColumnCollection`
        representing the columns that
        this SELECT statement or similar construct returns in its result set,
        not including :class:`_sql.TextClause` constructs.

        This collection differs from the :attr:`_expression.FromClause.columns`
        collection of a :class:`_expression.FromClause` in that the columns
        within this collection cannot be directly nested inside another SELECT
        statement; a subquery must be applied first which provides for the
        necessary parenthesization required by SQL.

        For a :func:`_expression.select` construct, the collection here is
        exactly what would be rendered inside the "SELECT" statement, and the
        :class:`_expression.ColumnElement` objects are directly present as they
        were given, e.g.::

            col1 = column('q', Integer)
            col2 = column('p', Integer)
            stmt = select(col1, col2)

        Above, ``stmt.selected_columns`` would be a collection that contains
        the ``col1`` and ``col2`` objects directly. For a statement that is
        against a :class:`_schema.Table` or other
        :class:`_expression.FromClause`, the collection will use the
        :class:`_expression.ColumnElement` objects that are in the
        :attr:`_expression.FromClause.c` collection of the from element.

        .. note::

            The :attr:`_sql.Select.selected_columns` collection does not
            include expressions established in the columns clause using the
            :func:`_sql.text` construct; these are silently omitted from the
            collection. To use plain textual column expressions inside of a
            :class:`_sql.Select` construct, use the :func:`_sql.literal_column`
            construct.


        .. versionadded:: 1.4

        )rb  r  r  r   rR   r  r   )r9   convr   s      r:   rx  zSelect.selected_columns  se    ^ 44T5F5FG 33(( a!
 ,.	s   A%c                 b    t         j                  |       j                  }t         ||             S r6   )rb  r  r  rQ  r  s     r:   rR   zSelect._all_selected_columns)  s'    ++D1FFDJr<   c                 T    | j                   t        u r| j                  t              } | S r6   )r  r  r  r  r8   s    r:   r  z"Select._ensure_disambiguated_names.  s'     00''(EFDr<   c                 V   || j                   }t        j                  | j                        }i }g }|j                  }| j                  t
        u }| j                  t        u }d}	|D ]  }
d}|
j                  sdx}x}}n|rdx}}|
j                  xs |
j                  }n|r|
j                  x}x}}n|
j                  x}}d}|t|
j                  }|`|
j                  |v }|
||
j                  <   dx}}|r0|r|
j                  |	      }|	dz  }	n*|
j                  |	      }|	dz  }	n|
j                  }n|x}x}}|||v rt        ||         t        |
      k7  r}|r|
j                  x}}n|
j                  x}}|rV||v rRt        ||         t        |
      k(  sJ |r|
j                  |	      x}}|	dz  }	n|
j                  |	      x}}|	dz  }	d}nC|
||<   n=|r;|r|
j                  |	      x}}|	dz  }	n|
j                  |	      x}}|	dz  }	d}n|
||<    || ||
      ||
|f        |S )ac  Generate column names as rendered in a SELECT statement by
        the compiler.

        This is distinct from the _column_naming_convention generator that's
        intended for population of .c collections and similar, which has
        different rules.   the collection returned here calls upon the
        _column_naming_convention as well.

        Nr   FT)rR   rb  r  r  rp  r  r  _render_label_in_columns_clause_non_anon_label_anon_name_labelr  _expression_label_dedupe_anon_tq_label_idx_dedupe_anon_label_idxr#  _anon_tq_label)r9   r  r  key_naming_conventionr  resultresult_appendr  label_style_nonededupe_hashr   repeatedeffective_namerequired_label_namefallback_label_name
expr_labels                   r:   r  z#Select._generate_columns_plus_names3  s&    <--D + E E!
 ++/MM,,0@@  @	AH44 +// /''!7;;!4&'&7&7&M1;M;M#" /0kk:' :&+;<;L;LLN%8*.'!) "#!4!4J!)#$#5#5#>45a001?CC)<#  /$%$?$?$L !4 !,q 0676N6N$/7" 3 !,q 0232D2D/ 3==+ =*/)!U* E.12d1g= + !" 0 01/ 3
 !" 2 23/ 3 -1D1M $(.A(B#CtAw#NN#N  / %&$?$?$L!M 3$7 +q 0 %&$<$<[$I!J 3$7 +q 0'+H9:E"56* + !" ; ;K HI/ 3'1,K !" 8 8 EF/ 3'1,K#',-E.) ( *!, ( ![@	D r<   c                     | j                  d      D cg c])  \  }}}}}|j                  s|j                  |||d      + }}}}}}|j                  j	                  |       yc c}}}}}w )zYGenerate column proxies to place in the exported ``.c``
        collection of a subquery.FT)r   rf   name_is_truncatableN)r  r  r   r   r   )r9   rG   rT  	proxy_keyrU  r   rR  proxs           r:   r   z*Select._generate_fromclause_column_proxies  s    " 33E:
 
##$$ MM($(	  
 
" 	11$7#
s   .A(c                 \    | j                   xs t        | j                  j                        S r6   )r  r\  r  r  r8   s    r:   _needs_parens_for_groupingz!Select._needs_parens_for_grouping  s+    ,, 
!!))1
 	
r<   c                 \    t        |t              r| j                         s| S t        |       S )a@  Return a 'grouping' construct as per the
        :class:`_expression.ClauseElement` specification.

        This produces an element that can be embedded in an expression. Note
        that this method is called automatically as needed when constructing
        expressions and should not require explicit use.

        )r6  r  r\  r  r&  s     r:   r  zSelect.self_group  s*     w/335K*400r<   c                 4    t        j                  | g|i |S )a  Return a SQL ``UNION`` of this select() construct against
        the given selectables provided as positional arguments.

        :param \*other: one or more elements with which to create a
         UNION.

         .. versionchanged:: 1.4.28

            multiple elements are now accepted.

        :param \**kwargs: keyword arguments are forwarded to the constructor
         for the newly created :class:`_sql.CompoundSelect` object.

        )r  r  r9   r   rJ   s      r:   r   zSelect.union  s     ++DC5CFCCr<   c                 4    t        j                  | g|i |S )a  Return a SQL ``UNION ALL`` of this select() construct against
        the given selectables provided as positional arguments.

        :param \*other: one or more elements with which to create a
         UNION.

         .. versionchanged:: 1.4.28

            multiple elements are now accepted.

        :param \**kwargs: keyword arguments are forwarded to the constructor
         for the newly created :class:`_sql.CompoundSelect` object.

        )r  r!  r_  s      r:   r  zSelect.union_all       //GuGGGr<   c                 4    t        j                  | g|i |S )a  Return a SQL ``EXCEPT`` of this select() construct against
        the given selectable provided as positional arguments.

        :param \*other: one or more elements with which to create a
         UNION.

         .. versionchanged:: 1.4.28

            multiple elements are now accepted.

        :param \**kwargs: keyword arguments are forwarded to the constructor
         for the newly created :class:`_sql.CompoundSelect` object.

        )r  r#  r_  s      r:   except_zSelect.except_(  s     ,,TDEDVDDr<   c                 4    t        j                  | g|i |S )a  Return a SQL ``EXCEPT ALL`` of this select() construct against
        the given selectables provided as positional arguments.

        :param \*other: one or more elements with which to create a
         UNION.

         .. versionchanged:: 1.4.28

            multiple elements are now accepted.

        :param \**kwargs: keyword arguments are forwarded to the constructor
         for the newly created :class:`_sql.CompoundSelect` object.

        )r  r&  r_  s      r:   
except_allzSelect.except_all9  s     00HHHHr<   c                 4    t        j                  | g|i |S )a  Return a SQL ``INTERSECT`` of this select() construct against
        the given selectables provided as positional arguments.

        :param \*other: one or more elements with which to create a
         UNION.

         .. versionchanged:: 1.4.28

            multiple elements are now accepted.

        :param \**kwargs: keyword arguments are forwarded to the constructor
         for the newly created :class:`_sql.CompoundSelect` object.

        )r  r(  r_  s      r:   	intersectzSelect.intersectJ  ra  r<   c                 4    t        j                  | g|i |S )a  Return a SQL ``INTERSECT ALL`` of this select() construct
        against the given selectables provided as positional arguments.

        :param \*other: one or more elements with which to create a
         UNION.

         .. versionchanged:: 1.4.28

            multiple elements are now accepted.

        :param \**kwargs: keyword arguments are forwarded to the constructor
         for the newly created :class:`_sql.CompoundSelect` object.

        )r  r+  r_  s      r:   intersect_allzSelect.intersect_all[  s     33DK5KFKKr<   r  r  r  c                 D   | j                   r| j                   S | j                         D ]K  }|j                  r#|j                  | u rt	        j
                  d      |j                  }|r|| _         |c S  n | j                  D ]  }|j                  }|s|| _         |c S  y)rF  r  N)r  r  r  r  r0   r  r  rn  )r9   r  rG  r   s       r:   r  zSelect.bindl  s     :::://1 	D  T\\T%9--C  		A
	 "" 	AA
		r<   c                     || _         y r6   rI  rJ  s     r:   r  zSelect.bind  rK  r<   )NNNFNTNNr  r  )Tr6   )jr=   r>   r?   rU   ru   rm  r  rl  r  r  r  r  r  r  rk  r  rb  ri  r  r.   r  dp_memoized_select_entitiesdp_clauseelement_tupler  r  rL  r  dp_plain_objr  r  rz   r   r   r   r   r   r   rM  r   _executable_traverse_internalsr  dp_has_cache_keyrh  r  r   r1   rw   rF   r  r  r  r  r  r.  r  r  r  rA   r  rx  r   r   r  r
  r   r  rd  r  r  r   r   r@  r   rU  r#  r^   rx   r.  r'  r   _whereclauserY  r\  r  r~  r  r@  r   r  rx  rR   r  r  r   r\  r  r   r  rc  re  rg  ri  r  r  rO  r  r  s   @r:   rE   rE     sV    NL "ILJOIO"AA .DDE+!== +AAB 1 H HI!2!I!IJ "3"J"JK "3"J"JK.BBC"$5$I$IJ,CCD "3"J"JK/@@A0AAB/@@A$&7&E&EF 1 B BC+667.EEF.;;<-	
0 
-
-1	.2 
6
63	74 
6
65	76 
0
07	18 #
H
H9	I: 
3
3;	4 B /	.??@2  4 4 T__	2 H HT 0 0d +N
 
 74 74r$
%
$% ) )V%. A
 A
F

 @E;
 ;
z#MJ%LN T__	A
& & 
 
( 
0 
0 %+ 4#l
 
 
.
 T__	1((  T./
 0
> J
 J
X 
 
  L6 6 
 
 " "( (
 (
T : :x # #J ##6 $6p ##  $ 
dL8.

1"D"H"E"I"H"L" T"K
 6 
[[ r<   rE   c                   p    e Zd ZdZg ZdZdZdZd Ze	d        Z
e
Zed        Zd Zed        Zed	        Zy
)r  a  Represent a scalar subquery.


    A :class:`_sql.ScalarSelect` is created by invoking the
    :meth:`_sql.SelectBase.scalar_subquery` method.   The object
    then participates in other SQL expressions as a SQL column expression
    within the :class:`_sql.ColumnElement` hierarchy.

    .. seealso::

        :meth:`_sql.SelectBase.scalar_subquery`

        :ref:`tutorial_scalar_subquery` - in the 2.0 tutorial

    TFc                 <    || _         |j                         | _        y r6   )r  r.  rj  r  s     r:   r  zScalarSelect.__init__  s    ((*	r<   c                 ,    t        j                  d      )NzcScalar Select expression has no columns; use this object directly within a column-level expression.)r0   r  r8   s    r:   r   zScalarSelect.columns  s    %%0
 	
r<   c                 D    | j                   j                  |      | _         y)zuApply a WHERE clause to the SELECT statement referred to
        by this :class:`_expression.ScalarSelect`.

        N)r  rY  )r9   rZ  s     r:   rY  zScalarSelect.where  s     ||))$/r<   c                     | S r6   rB   )r9   rJ   s     r:   r  zScalarSelect.self_group  r  r<   c                 @     | j                   j                  | | _         y)a  Return a new :class:`_expression.ScalarSelect`
        which will correlate the given FROM
        clauses to that of an enclosing :class:`_expression.Select`.

        This method is mirrored from the :meth:`_sql.Select.correlate` method
        of the underlying :class:`_sql.Select`.  The method applies the
        :meth:_sql.Select.correlate` method, then returns a new
        :class:`_sql.ScalarSelect` against that statement.

        .. versionadded:: 1.4 Previously, the
           :meth:`_sql.ScalarSelect.correlate`
           method was only available from :class:`_sql.Select`.

        :param \*fromclauses: a list of one or more
         :class:`_expression.FromClause`
         constructs, or other compatible constructs (i.e. ORM-mapped
         classes) to become part of the correlate collection.

        .. seealso::

            :meth:`_expression.ScalarSelect.correlate_except`

            :ref:`tutorial_scalar_subquery` - in the 2.0 tutorial


        N)r  r  r<  s     r:   r  zScalarSelect.correlate  s    8 .t||--{;r<   c                 @     | j                   j                  | | _         y)a  Return a new :class:`_expression.ScalarSelect`
        which will omit the given FROM
        clauses from the auto-correlation process.

        This method is mirrored from the
        :meth:`_sql.Select.correlate_except` method of the underlying
        :class:`_sql.Select`.  The method applies the
        :meth:_sql.Select.correlate_except` method, then returns a new
        :class:`_sql.ScalarSelect` against that statement.

        .. versionadded:: 1.4 Previously, the
           :meth:`_sql.ScalarSelect.correlate_except`
           method was only available from :class:`_sql.Select`.

        :param \*fromclauses: a list of one or more
         :class:`_expression.FromClause`
         constructs, or other compatible constructs (i.e. ORM-mapped
         classes) to become part of the correlate-exception collection.

        .. seealso::

            :meth:`_expression.ScalarSelect.correlate`

            :ref:`tutorial_scalar_subquery` - in the 2.0 tutorial


        N)r  r@  r<  s     r:   r@  zScalarSelect.correlate_except  s    < 5t||44kBr<   N)r=   r>   r?   rU   r   r  _is_implicitly_booleanr@   r  rA   r   r   r   rY  r  r  r@  rB   r<   r:   r  r    s      M"M+ 
 
 	A0 0 < <: C Cr<   r  c                   r    e Zd ZdZg ZdZd Zd Z ej                  dd      dd	       Z
d
 Zd Zd Zd Zy)r  zRepresent an ``EXISTS`` clause.

    See :func:`_sql.exists` for a description of usage.

    An ``EXISTS`` clause can also be constructed from a :func:`_sql.select`
    instance by calling :meth:`_sql.SelectBase.exists`.

    Tc                    |rt        |d   t        t        f      r|d   }n1|st        d      f}t	        j
                  |i |j                         }t        j                  | |t        j                  t        j                  d       y)a  Construct a new :class:`_expression.Exists` construct.

        The :func:`_sql.exists` can be invoked by itself to produce an
        :class:`_sql.Exists` construct, which will accept simple WHERE
        criteria::

            exists_criteria = exists().where(table1.c.col1 == table2.c.col2)

        However, for greater flexibility in constructing the SELECT, an
        existing :class:`_sql.Select` construct may be converted to an
        :class:`_sql.Exists`, most conveniently by making use of the
        :meth:`_sql.SelectBase.exists` method::

            exists_criteria = (
                select(table2.c.col2).
                where(table1.c.col1 == table2.c.col2).
                exists()
            )

        The EXISTS criteria is then used inside of an enclosing SELECT::

            stmt = select(table1.c.col1).where(exists_criteria)

        The above statement will then be of the form::

            SELECT col1 FROM table1 WHERE EXISTS
            (SELECT table2.col2 FROM table2 WHERE table2.col2 = table1.col1)

        .. seealso::

            :ref:`tutorial_exists` - in the :term:`2.0 style` tutorial.

            :meth:`_sql.SelectBase.exists` - method to transform a ``SELECT`` to an
            ``EXISTS`` clause.

        r   r   T)operatorr  wraps_column_expressionN)r6  rt  r  r+   rE   r  r  r-   r  r   r  r	   BOOLEANTYPE)r9   rI   rJ   r  s       r:   r  zExists.__init__  sx    J JtAw\(BCQA&s+-//??AA  %%&&$(	
r<   c                     | j                   j                         } ||      }|j                  t        j                        S )Nr  )r  _ungroupr  r   r  )r9   fnr  s      r:   _regroupzExists._regroupA  s7    ,,'')W+!!)*:*:!;;r<   )r   zThe :paramref:`_sql.Exists.select().whereclause` parameter is deprecated and will be removed in version 2.0.  Please make use of the :meth:`.Select.where` method to add WHERE criteria to the SELECT statement.)r   zThe :meth:`_sql.Exists.select` method will no longer accept keyword arguments in version 2.0.  Please use generative methods from the :class:`_sql.Select` construct in order to apply additional modifications.r   Nc                 @    |||d<   t        j                  | | gfi |S )a  Return a SELECT of this :class:`_expression.Exists`.

        e.g.::

            stmt = exists(some_table.c.id).where(some_table.c.id == 5).select()

        This will produce a statement resembling::

            SELECT EXISTS (SELECT id FROM some_table WHERE some_table = :param) AS anon_1

        :param whereclause: a WHERE clause, equivalent to calling the
         :meth:`_sql.Select.where` method.

        :param **kwargs: additional keyword arguments are passed to the
         legacy constructor for :class:`_sql.Select` described at
         :meth:`_sql.Select.create_legacy_select`.

        .. seealso::

            :func:`_expression.select` - general purpose
            method which allows for arbitrary column lists.

        r   r   r   s      r:   r   zExists.selectF  s/    V "$/F=!44TD6LVLLr<   c                 Z    | j                         }| j                  fd      |_        |S )zApply correlation to the subquery noted by this
        :class:`_sql.Exists`.

        .. seealso::

            :meth:`_sql.ScalarSelect.correlate`

        c                 "     | j                    S r6   )r  r  r   s    r:   re  z"Exists.correlate.<locals>.<lambda>  s    -G--z: r<   r   r  r  r9   r   rG  s    ` r:   r  zExists.correlateu  s*     KKMMM:
	 r<   c                 Z    | j                         }| j                  fd      |_        |S )zApply correlation to the subquery noted by this
        :class:`_sql.Exists`.

        .. seealso::

            :meth:`_sql.ScalarSelect.correlate_except`

        c                 "     | j                    S r6   )r@  r  s    r:   re  z)Exists.correlate_except.<locals>.<lambda>  s    4G44jA r<   r  r  s    ` r:   r@  zExists.correlate_except  s*     KKMMMA
	 r<   c                 Z    | j                         }| j                  fd      |_        |S )a  Return a new :class:`_expression.Exists` construct,
        applying the given
        expression to the :meth:`_expression.Select.select_from`
        method of the select
        statement contained.

        .. note:: it is typically preferable to build a :class:`_sql.Select`
           statement first, including the desired WHERE clause, then use the
           :meth:`_sql.SelectBase.exists` method to produce an
           :class:`_sql.Exists` object at once.

        c                 "     | j                    S r6   )r~  )r  rd  s    r:   re  z$Exists.select_from.<locals>.<lambda>  s    2E'2E2Eu2M r<   r  )r9   rd  rG  s    ` r:   r~  zExists.select_from  s&     KKMMM"MN	r<   c                 Z    | j                         }| j                  fd      |_        |S )a  Return a new :func:`_expression.exists` construct with the
        given expression added to
        its WHERE clause, joined to the existing clause via AND, if any.


        .. note:: it is typically preferable to build a :class:`_sql.Select`
           statement first, including the desired WHERE clause, then use the
           :meth:`_sql.SelectBase.exists` method to produce an
           :class:`_sql.Exists` object at once.

        c                 "     | j                    S r6   r  )r  r  s    r:   re  zExists.where.<locals>.<lambda>  s    -'--2H r<   r  )r9   r  rG  s    ` r:   rY  zExists.where  s&     KKMMM"HI	r<   r6   )r=   r>   r?   rU   r   r@   r  r  r1   r	  r   r  r@  r~  rY  rB   r<   r:   r  r     s_     MM2
h<
 T

$M%$M: "r<   r  c                       e Zd ZdZdZeZdej                  fdej                  fge
j                  z   ZdZdZdZddZej$                  d        Zed        Zd	 Zd
 Zed        Zed        Zd Zd Zy)TextualSelectaF  Wrap a :class:`_expression.TextClause` construct within a
    :class:`_expression.SelectBase`
    interface.

    This allows the :class:`_expression.TextClause` object to gain a
    ``.c`` collection
    and other FROM-like capabilities such as
    :meth:`_expression.FromClause.alias`,
    :meth:`_expression.SelectBase.cte`, etc.

    The :class:`_expression.TextualSelect` construct is produced via the
    :meth:`_expression.TextClause.columns`
    method - see that method for details.

    .. versionchanged:: 1.4 the :class:`_expression.TextualSelect`
       class was renamed
       from ``TextAsFrom``, to more correctly suit its role as a
       SELECT-oriented object and not a FROM clause.

    .. seealso::

        :func:`_expression.text`

        :meth:`_expression.TextClause.columns` - primary creation interface.

    textual_selectr  column_argsTc                     || _         |D cg c]&  }t        j                  t        j                  |      ( c}| _        || _        y c c}w r6   )r  r   r   r   r`  r  
positional)r9   r   r   r  r   s        r:   r  zTextualSelect.__init__  sF     CJ
=>IU44a8
 %
s   +Ac                 V    t        d | j                  D              j                         S )am  A :class:`_expression.ColumnCollection`
        representing the columns that
        this SELECT statement or similar construct returns in its result set,
        not including :class:`_sql.TextClause` constructs.

        This collection differs from the :attr:`_expression.FromClause.columns`
        collection of a :class:`_expression.FromClause` in that the columns
        within this collection cannot be directly nested inside another SELECT
        statement; a subquery must be applied first which provides for the
        necessary parenthesization required by SQL.

        For a :class:`_expression.TextualSelect` construct, the collection
        contains the :class:`_expression.ColumnElement` objects that were
        passed to the constructor, typically via the
        :meth:`_expression.TextClause.columns` method.


        .. versionadded:: 1.4

        c              3   8   K   | ]  }|j                   |f  y wr6   rf  r)  s     r:   r   z1TextualSelect.selected_columns.<locals>.<genexpr>  s       
QUUAJ 
r,  )r   r  r   r8   s    r:   rx  zTextualSelect.selected_columns  s+    ,    
 $ 0 0 
 

,.	r<   c                     | j                   S r6   )r  r8   s    r:   rR   z#TextualSelect._all_selected_columns  s    r<   c                     | S r6   rB   r  s     r:   r4  zTextualSelect._set_label_style  r  r<   c                     | S r6   rB   r8   s    r:   r  z)TextualSelect._ensure_disambiguated_names	  r  r<   c                 .    | j                   j                  S r6   )r  r  r8   s    r:   r  zTextualSelect._bind  s    ||!!!r<   c                 F     | j                   j                  |i || _         y r6   )r  
bindparams)r9   bindsbind_as_valuess      r:   r  zTextualSelect.bindparams  s    .t||..HHr<   c                 b    j                   j                  fd| j                  D               y )Nc              3   @   K   | ]  }|j                          y wr6   r   )r   r   r   s     r:   r   zDTextualSelect._generate_fromclause_column_proxies.<locals>.<genexpr>  s      4
*+AMM*%4
r   )r   r   r  r   s    `r:   r   z1TextualSelect._generate_fromclause_column_proxies  s*    33 4
/3/?/?4
 	
r<   c                 4    | j                   d   j                  S r-  )r  rj  r8   s    r:   r.  zTextualSelect._scalar_type  s    "'''r<   Nrt   )r=   r>   r?   rU   ru   r  r  r.   r  r  r   rM  r  _is_textualis_textr  r  r   r  rx  rA   rR   r4  r  r  r   r  r   r.  rB   r<   r:   r  r    s    6 &N#L 
%667	)??@ 	!FFG
 KGI% ## $2     " " I I

(r<   r  c                       e Zd Zd Zy)AnnotatedFromClausec                 J    |j                    t        j                  | ||       y r6   )r   r   r  )r9   r  rR  s      r:   r  zAnnotatedFromClause.__init__"  s     			4&1r<   Nr  rB   r<   r:   r  r  !  s    2r<   r  )qrU   rh  r0  r|  r   rK  r   r   r   r   r	   r
   
annotationr   r   baser   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   ry  r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r0   r1   
inspectionr2   r4   rw   rG   r  rL   r[   objectrz   r   r   AnonymizedFromClauseRoler   rN  r  r  r  r  DMLTableRoler   r  r  r   r  rc   r   r  r  r  r  r  r%  r1  rO  rd  r
  DMLSelectRoler  InElementRolert  r  r  r  
plugin_forr	  r  rQ  MemoizedSlotsrb  r  HasCacheKeyHasCopyInternalsTraversibler  rE   r  r  r  
TextAsFromr  rB   r<   r:   <module>r     s2            ! 0  $ & '     # " "   (   !   ! . &  # ' #   " $  $ ' % '    $ $ 	I

H

H<$%'' <$~K
 K
\5
& 5
p0
& 0
fQv Qh%// %D 4;; . "-$" > !,#! 6 4 K	K5z K	K\
V 
.X! X!vG&E 2 G&Teu eP0  0fR$ Rj`F		OO`FF@
U @
F
F
! F
R,(>: ,(^o%$$i od:= :z@Z @F_(				
_(D	J*nj J*Z25f 25jr6
 rj $56,  7__&6 _D	}:& }:@ H-I&$$$l I& .I&X& 2'/J779M9M'/Tmm`5kC5&&
H kC\s_ sld(J d(N 
 42) 2r<   