
    -hk                       S r SSKrSSKrSSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SS	KJ
r
  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r   SSKJ!r!  SSKJ"r"  SS KJ#r#  SS!K$J%r%  SS"K$J&r&  SS#K$J'r'  SS$K$J(r(  SS%K$J)r)  SS&K$J*r*  SS'K$J+r+  SS(K$J,r,  SS)K$J-r-  SS*K$J.r.  SS+K$J/r/  SS,K$J0r0  SS-KJ1r1  S.S/KJ2r2  S.S0KJ3r3  S.S1K4J5r5   " S2 S3\'5      r6\3Rn                  " S4S55      S6 5       r8 " S7 S8\Rr                  \)5      r: " S9 S:\:5      r; " S; S<\<5      r= " S= S>\<5      r> " S? S@\<5      r? " SA SB\R                  \;5      rA\3R                  " SCSD5      rC\3R                  " SESF5      rD\3R                  " SGSH5      rE\ErF  " SI SJ\R                  \A5      rH " SK SL\<5      rI " SM SN\I\A5      rJ " SO SP\R                  \J5      rK " SQ SR\K5      rL " SS ST\J5      rM " SU SV\J5      rN " SW SX\R                  \R                  \\=\>\J5      rP " SY SZ\R                  5      rR " S[ S\\J5      rS " S] S^\,\A5      rT " S_ S`\R                  \!\A5      rU " Sa Sb\)5      rV " Sc Sd\\A5      rW " Se Sf\R                  \R                  \R                  \R                  \R\\\;5
      r\ " Sg Sh\,\\5      r] " Si Sj\<5      r^ " Sk Sl\^\\5      r_\R                  " SmSn5       " So Sp\5      5       ra " Sq Sr\\_5      rb " Ss St\<5      rc\R                  " SmSu5       " Sv Sw\3R                  \5      5       re " Sx Sy\<5      rf " Sz S{\	R                  \	R                  \R                  5      rj " S| S}\=\>\?\\c\f\_5	      rk " S~ S\R                  \\-5      rl " S S\05      rm " S S\\5      rn\nro  " S S\5      rpg)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                   (    \ rS rSrSr\S 5       rSrg)_OffsetLimitParam@   Tc                     U R                   $ N)effective_valueselfs    nC:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\sqlalchemy/sql/selectable.py_limit_offset_value%_OffsetLimitParam._limit_offset_valueC   s    ###     N)__name__
__module____qualname____firstlineno__inherit_cachepropertyr<   __static_attributes__r?   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                 L    [         R                  " U0 UD6R                  U 5      $ )zReturn 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;   rK   rK   H   s%     &&77@@GGr>   c                   X    \ rS rSrSrSrSrSrSr\	S 5       r
\	S 5       r\	S 5       rSrg	)
ReturnsRowsZ   a  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                     U $ r7   r?   r9   s    r;   
selectableReturnsRows.selectablen   s    r>   c                     [        5       e)a  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`.

NotImplementedErrorr9   s    r;   _all_selected_columns!ReturnsRows._all_selected_columnsr   s     "##r>   c                     [        5       e)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`
rV   r9   s    r;   exported_columnsReturnsRows.exported_columns~   s    0 "##r>   r?   N)r@   rA   rB   rC   __doc___is_returns_rows_is_from_clause_is_select_statement_is_lateralrE   rS   rX   r[   rF   r?   r>   r;   rP   rP   Z   s[    
  O K  	$ 	$ $ $r>   rP   c                       \ rS rSrSrSrSrS rSS jr\	R                  " SS	S
9\	R                  " S5      S 5       5       rSS jrSrg)
Selectable   z!Mark a class as being selectable.rS   Tc                     [        5       er7   rV   r:   columns     r;   _refresh_for_new_column"Selectable._refresh_for_new_column       !##r>   Nc                 ,    [         R                  X5      $ a*  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r:   names     r;   lateralSelectable.lateral   s     !!$--r>   rG   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    [         R                  R                  R                  U5      R	                  U 5      $ )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)r:   oldrL   s      r;   replace_selectableSelectable.replace_selectable   s*     ~~&&44U;DDTJJr>   c                 8    U R                   R                  X5      $ )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.

)r[   corresponding_column)r:   rg   require_embeddeds      r;   r~   Selectable.corresponding_column   s!    B $$99
 	
r>   r?   r7   F)r@   rA   rB   rC   r]   __visit_name__is_selectablerh   rq   r1   
deprecatedpreload_moduler{   r~   rF   r?   r>   r;   rc   rc      s\    +!NM$. 
__M 
./K 0K#
r>   rc   c                   j    \ rS rSrSrS\R                  4/r\\	" SSS5      S 5       5       r
SS	 jrS
rg)HasPrefixes   r?   	_prefixesexprz+:meth:`_expression.HasPrefixes.prefix_with`z*:paramref:`.HasPrefixes.prefix_with.*expr`c                     UR                  SS5      nU(       a(  [        R                  " SSR                  U5      -  5      eU R	                  X5        g)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r:   r   kwr   s       r;   prefix_withHasPrefixes.prefix_with   sK    B &&D)##-<  	T+r>   Nc           
          U R                   [        U Vs/ s H*  n[        R                  " [        R
                  U5      U4PM,     sn5      -   U l         g s  snf r7   )r   tupler   expectr   StatementOptionRole)r:   prefixesr   ps       r;   r   HasPrefixes._setup_prefixes  S    % "!A !!%";";Q?I!+
 
   1A
)r   r7   )r@   rA   rB   rC   r   r.   dp_prefix_sequence _has_prefixes_traverse_internalsr   r!   r   r   rF   r?   r>   r;   r   r      sP    I 
'::;($ 54
 ,  ,D
r>   r   c                   j    \ rS rSrSrS\R                  4/r\\	" SSS5      S 5       5       r
SS	 jrS
rg)HasSuffixesi  r?   	_suffixesr   z+:meth:`_expression.HasSuffixes.suffix_with`z*:paramref:`.HasSuffixes.suffix_with.*expr`c                     UR                  SS5      nU(       a(  [        R                  " SSR                  U5      -  5      eU R	                  X5        g)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_withHasSuffixes.suffix_with&  sJ    8 &&D)##-<  	T+r>   Nc           
          U R                   [        U Vs/ s H*  n[        R                  " [        R
                  U5      U4PM,     sn5      -   U l         g s  snf r7   )r   r   r   r   r   r   )r:   suffixesr   r   s       r;   r   HasSuffixes._setup_suffixesI  r   r   )r   r7   )r@   rA   rB   rC   r   r.   r    _has_suffixes_traverse_internalsr   r!   r   r   rF   r?   r>   r;   r   r     sO    I 
'::;($ 54
, ,:
r>   r   c                       \ rS rSr\R
                  " 5       rSrS\R                  4S\R                  4/rS	S jr\S	S j5       rSrg)
HasHintsiR  r?   _statement_hints_hintsc                 &    U R                  SX5      $ )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)r:   textdialect_names      r;   with_statement_hintHasHints.with_statement_hint[  s    0 ~~dD77r>   c                     Uc  U =R                   X244-  sl         gU R                  R                  [        R                  " [
        R                  U5      U4U05      U l        g)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)r:   rS   r   r   s       r;   r   HasHints.with_hintu  sb    H !!|&:%<<!++++ "(()=)=zJ$ 	DKr>   )r   N)*)r@   rA   rB   rC   r1   immutabledictr   r   r.   dp_statement_hint_listdp_table_hint_list_has_hints_traverse_internalsr   r   r   rF   r?   r>   r;   r   r   R  sW    !F 
.EEF	$778%!
84 - -r>   r   c                      \ rS rSrSrSrSr/ rSr Sr	Sr
SrSr\R                  " SSS	9S$S
 j5       rS%S jrS&S jrS&S jr\R&                  " S5      S 5       rS'S jrS rS r\S 5       rS r\S 5       r\R8                  S 5       r\S 5       r\R8                  S 5       r\R8                  S 5       r S r!\" \"" S5      SS9r#\" \"" S5      5      r$S r%\S 5       r&S  r'S! r(S&S" jr)S#r*g)(
FromClausei  a  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.whereclauserN   c                 @    Ub  XS'   [         R                  " X /40 UD6$ )a  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   rI   _create_select_from_fromclauser:   r   rN   s      r;   selectFromClause.select  s+    N "$/=!44T6LVLLr>   c                     [        XX#U5      $ )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)r:   rightonclauseisouterfulls        r;   r   FromClause.join  s    X DD99r>   c                     [        XUSU5      $ )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   )r:   r   r   r   s       r;   	outerjoinFromClause.outerjoin'  s    X D466r>   c                 ,    [         R                  X5      $ )a,  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`

)Aliasrn   r:   rp   flats      r;   rL   FromClause.aliasU  s    & ++r>   zsqlalchemy.sql.sqltypesc                 6    [        U [        R                  5      $ )a  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	   
TABLEVALUEr9   s    r;   table_valuedFromClause.table_valuedj  s    4 !x':':;;r>   c                 .    [         R                  XX#5      $ )a>  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

)TableSamplern   )r:   samplingrp   seeds       r;   tablesampleFromClause.tablesample  s     %%ddAAr>   c                     XR                   ;   $ )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r:   r   s     r;   is_derived_fromFromClause.is_derived_from  s     ----r>   c                 L    U R                   R                  UR                   5      $ )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r:   others     r;   _is_lexical_equivalent!FromClause._is_lexical_equivalent  s!     ,,U->->??r>   c                 J    [        U SU R                  R                  S-   5      $ )zlA brief description of this :class:`_expression.FromClause`.

Used primarily for error message formatting.

rp   z object)getattr	__class__r@   r9   s    r;   descriptionFromClause.description  s"     tVT^^%<%<y%HIIr>   c                 d   ^ TR                   R                  U4S jU R                   5       5        g )Nc              3   D   >#    U  H  oR                  T5      v   M     g 7fr7   _make_proxy).0colr   s     r;   	<genexpr>AFromClause._generate_fromclause_column_proxies.<locals>.<genexpr>  s      4
39COOJ''6    )_columns_populate_separate_keyscr   s    `r;   #_generate_fromclause_column_proxies.FromClause._generate_fromclause_column_proxies  s(    33 4
37664
 	
r>   c                     U R                   $ )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`


columnsr9   s    r;   r[   FromClause.exported_columns  s    ( ||r>   c                     SU R                   ;  a   U R                  5         U R                  5         U R                  R	                  5       $ )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_immutabler9   s    r;   r  FromClause.columns  s;     T]]*""$,,.}}))++r>   c                     U R                   $ )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  r9   s    r;   entity_namespaceFromClause.entity_namespace  s     ||r>   c                 Z    U R                  5         U R                  5         U R                  $ )aH  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_keyr9   s    r;   r  FromClause.primary_key  s(     	 ((*r>   c                 Z    U R                  5         U R                  5         U R                  $ )a  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_keysr9   s    r;   r  FromClause.foreign_keys  s(     	 ((*   r>   c                 N    S H  nU R                   R                  US5        M!     g)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   )r:   keys     r;   _reset_column_collection#FromClause._reset_column_collection  s$     JCMMc4( J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                     SU R                   ;  d   eSU R                   ;  d   eSU R                   ;  d   e[        5       U l        [        5       U l        [        5       U l        g )Nr   r  r  )r	  r   r   r   r  setr  r9   s    r;   r
  FromClause._init_collections4  sV    ...DMM111T]]222(*$;Er>   c                      SU R                   ;   $ )Nr   )r	  r9   s    r;   _cols_populatedFromClause._cols_populated=  s    T]]**r>   c                     g)zCalled on subclasses to establish the .c collection.

Each implementation has a different way of establishing
this collection.

Nr?   r9   s    r;   r  &FromClause._populate_column_collectionA  s    r>   c                 $    U R                  5         g)a  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  rf   s     r;   rh   "FromClause._refresh_for_new_columnI  s    2 	%%'r>   c                      U R                  US9$ Nrp   )rL   r   s      r;   _anonymous_fromclause FromClause._anonymous_fromclaused  s    zztz$$r>   )r   r  r  r7   NFFNFNN)+r@   rA   rB   rC   r]   r   named_with_column_hide_fromsschemar   r_   _is_join_use_schema_mapr1   deprecated_paramsr   r   r   rL   r   r   r   r   r   rE   r   r  r[   memoized_propertyr  r  r  r  r  r   r  _select_iterabler
  r   r  rh   r)  rF   r?   r>   r;   r   r     s   ( "NKF MOHO	

$M%$M2,:\,7\,* 
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                     ^  \ rS rSrSrSrS\R                  4S\R                  4S\R                  4S\R                  4S\R                  4/r	S	r
S*S jr\S+S j5       r\ S*S j5       r\S 5       rS rS,S jr\R(                  " S5      S 5       r\4U 4S jjrU 4S jrS r\ S-S j5       r\S,S j5       r\\R(                  " S5      S 5       5       r\S 5       r\R<                  " SSS9S,S j5       r\\R@                  " SSS
S 9S! 5       5       r!\R(                  " S5      S+S" j5       r"\R@                  " S#S$S%9S+S& j5       r#\S' 5       r$\S( 5       r%S)r&U =r'$ ).r   i  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                    [         R                  " [        R                  USS9U l        [         R                  " [        R                  USS9R                  5       U l        Uc,  U R                  U R                  U R                  5      U l        OE[         R                  " [        R                  U5      R                  [        R                  S9U l        X@l        XPl        g)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   )r:   r:  r   r   r   r   s         r;   __init__Join.__init__  s     $$  $4
	 %%  %D

*, 	
  11$))TZZHDM &,,""Hj!2!2j3 M 	r>   c                     U " XUSUS9$ )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   r?   )clsr:  r   r   r   s        r;   _create_outerjoinJoin._create_outerjoin  s    0 4$TBBr>   c                     U " XX4U5      $ )a>  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.

r?   )rG  r:  r   r   r   r   s         r;   _create_joinJoin._create_join  s    h 4488r>   c                     SU R                   R                  [        U R                   5      U R                  R                  [        U R                  5      4-  $ )Nz Join object on %s(%d) and %s(%d))r:  r   idr   r9   s    r;   r   Join.descriptionM  sD    1II!!tyyMJJ""tzzN	5
 
 	
r>   c                     [        U5      [        U 5      :H  =(       d=    U R                  R                  U5      =(       d    U R                  R                  U5      $ r7   )hashr:  r   r   r   s     r;   r   Join.is_derived_fromV  sH     T
* 6yy((46zz))*5	
r>   c                     [        U 5      $ r7   )FromGroupingr:   r>  s     r;   r?  Join.self_group_  s    D!!r>   rt   c                 8   [         R                  R                  nU R                  R                   Vs/ s H  o"PM     snU R
                  R                   Vs/ s H  o"PM     sn-   nU R                  R                  UR                  S U 5       U R                  5      5        U R                  R                  S U 5       5        U R                  R                  [        R                  " U Vs/ s H  oDR                  PM     sn6 5        g s  snf s  snf s  snf )Nc              3   J   #    U  H  oR                   (       d  M  Uv   M     g 7fr7   )r  r   r  s     r;   r   3Join._populate_column_collection.<locals>.<genexpr>k  s     5Gq}}Gs   #	#c              3   <   #    U  H  oR                   U4v   M     g 7fr7   )_tq_key_label)r   r   s     r;   r   rZ  n  s      .
07$   )r1   rv   rw   r:  r  r   r  extendreduce_columnsr   r   r   r  update	itertoolschain)r:   sqlutilr  r  r   s        r;   r   Join._populate_column_collectionb  s    ..))"ii//0/1/0zz))4
)!A)4
 
 	""5G5t}}	

 	-- .
07.
 	
 	  OO'B'3..'BC	
 1 4
 Cs   DD/Dc           	      2  >^ [        [        R                  " [        U R                  5      [        U R
                  5      5      5      nU Vs0 s H  oDU" U40 UD6_M     snmU4S jnXRS'   [        [        U ]"  " SSU0UD6  U R                  5         g s  snf )Nc                    > [        U [        5      (       a1  U R                  T;   a   TU R                     R                  U 5      nU$ g g r7   
isinstancer(   tabler~   objr   newelem	new_fromss      r;   replace%Join._copy_internals.<locals>.replace  B    #|,,i1G#CII.CCCH 2H,r>   rn  cloner?   )
r  ra  rb  r   r:  r   superr   _copy_internals_reset_memoizations)r:   rq  r   all_the_fromsfrn  rm  r   s         @r;   rs  Join._copy_internalsu  s    
 OOdii(djj)
 1>>1a2&>	
	
  9
 	dD)<<<  "# ?s   Bc                    > [         [        U ]  U5        U R                  R                  U5        U R                  R                  U5        g r7   )rr  r   rh   r:  r   r:   rg   r   s     r;   rh   Join._refresh_for_new_column  s6    dD1&9		))&1

**62r>   c                 j    [        U[        5      (       a  UR                  nOS nU R                  XUS9$ )N)a_subset)rh  r   r   _join_condition)r:   r:  r   
left_rights       r;   r@  Join._match_primaries  s3    dD!!JJ##D*#EEr>   c                    U R                  XX$5      n[        U5      S:  a  U R                  XXT5        [        U5      S:X  aP  [        U[        5      (       a  SnOSn[
        R                  " SUR                  < SUR                  < SU< 35      e[        UR                  5       5      S    VVs/ s H	  u  pxXx:H  PM     n	nn[        U	5      S:X  a  U	S   $ [        U	6 $ s  snnf )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_constraintsrh  rT  r0   NoForeignKeysErrorr   listvaluesr#   )
rG  abr|  consider_as_foreign_keysconstraintshintxycrits
             r;   r}  Join._join_condition  s    4 33
 {a**k {q !\**. 
 (( ==!--7  &*+*<*<*>%?%BC%BTQ%BCt9>7N;	 Ds   2C!c                     [        U[        5      (       a  UR                  nOS nU R                  UUUUS9n[	        U5      $ )N)r  r  r|  r  )rh  r   r   r  bool)rG  r:  r   r  r~  r  s         r;   	_can_joinJoin._can_join  sK    dD!!JJ33%=	 4 
 K  r>   c                    [         R                  R                  n[        R                  " [
        R                  U5      n[        R                  " [
        R                  U5      n[        R                  " [        5      nX!4 H  nUc  M  [        UR                  S S9 HW  nUb  UR                  U;  a  M   UR                  U5      n	U	c  M/  XhR&                     R)                  XR                  45        MY     XsLap  [        UR                  S S9 HW  nUb  UR                  U;  a  M   UR                  U5      n	U	c  M/  XhR&                     R)                  XR                  45        MY     U(       d  M    U$    U$ ! [        R                   aM  n
UR!                  U5       Vs1 s H  oR"                  iM     Os  snf nnU
R$                  U;   a  e  S n
A
GM;  S n
A
ff = f! [        R                   aM  n
UR!                  U5       Vs1 s H  oR"                  iM     Os  snf nnU
R$                  U;   a  e  S n
A
GM+  S n
A
ff = f)Nc                 .    U R                   R                  $ r7   parent_creation_orderfks    r;   <lambda>0Join._joincond_scan_left_right.<locals>.<lambda>  s    ryy/H/Hr>   r  c                 .    U R                   R                  $ r7   r  r  s    r;   r  r    s    bii6O6Or>   )r1   rv   rw   r   r   r   r   collectionsdefaultdictr  sortedr  r  get_referentr0   NoReferenceErrorfind_tablesrp   
table_name
constraintappend)rG  r  r|  r  r  rw   r  r:  r  r   nrtettable_namess                r;   r  Join._joincond_scan_left_right  s   
 >>**U1115U1115!--d3MD|$H -8		)AA!//$/C ?.55sII6FG%& } %%+OB 1<II-EE % ooa0 #MM2993		:JK%& {Y "X ? ++ !3;3G3G3M"N3Ma663M"NK"N+5 !( // %7?7K7KA7N&O7N!vv7N&O&O??k9!$%sH   8E>,G">GG%F;
:GG"I6H>	H
H>>Ic                    U(       a?  [        U5       H0  n[        S UR                   5       5      [        U5      :w  d  M.  X5	 M2     [        U5      S:  aC  [        S UR	                  5        5       5      n[        U5      S:X  a  [        U5      S   nXsU   0n[        U5      S:w  a3  [
        R                  " SUR                  < SUR                  < S35      eg )Nc              3   8   #    U  H  oR                   v   M     g 7fr7   )r  r   rv  s     r;   r   2Join._joincond_trim_constraints.<locals>.<genexpr>,  s     8Axx   r   c              3   8   #    U  H  n[        U5      v   M     g 7fr7   )r   )r   r  s     r;   r   r  4  s     F1Et1Er  r   zCan't determine join between 'r  z'; tables have more than one foreign key constraint relationship between them. Please specify the 'onclause' of this join explicitly.)r  r  elementsr  r  r0   AmbiguousForeignKeysErrorr   )rG  r  r  r  r  constdeduper  s           r;   r  Join._joincond_trim_constraints#  s     $k*888C,=  $*	 + {aF1C1C1EFFF6{a;'*"$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                     U R                   U R                  /nUb  XS'   [        R                  " X40 UD6R	                  U 5      $ )am  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   rI   r   select_from)r:   r   rN   collists       r;   r   Join.selectB  sM    R 99djj)"$/=!44
#

+d
	r>   :attr:`.Executable.bind`5Bound metadata is being removed as of SQLAlchemy 2.0.alternativeenable_warningsc                 h    U R                   R                  =(       d    U R                  R                  $ )zcReturn the bound engine associated with either the left or right
side of this :class:`_sql.Join`.

)r:  bindr   r9   s    r;   r  	Join.binds  s     yy~~00r>   c                 6   [         R                  R                  nU(       a  Ub  [        R                  " S5      eU R
                  R                  SS9U R                  R                  SS9pTUR                  U5      R                  UR                  U5      5      nUR                  UUR                  U R                  5      U R                  U R                  S9$ U R                  5       R!                  ["        5      R%                  S 5      R'                  U5      $ )Nz"Can't send name argument with flatT)r   rF  )r1   rv   rw   r0   r   r:  r)  r   rx   rb  r   ry   r   r   r   r   set_label_styler7  	correlaterL   )r:   rp   r   rc  left_aright_aadapters          r;   r)  Join._anonymous_fromclause  s    ..))''(LMM		//T/:

00d0;  ++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                      U R                  X!S9$ )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   rp   )r)  r   s      r;   rL   
Join.alias  s    L ))t)??r>   c           	          [         R                  " U R                   Vs/ s H#  n[        UR                  UR
                  5      PM%     sn6 $ s  snf r7   )ra  rb  r   r   r:  r   )r:   r  s     r;   r/  Join._hide_froms  s?    6:6F6FG6FmAFFAGG,6FG
 	
Gs   *Ac                 d    U /U R                   R                  -   U R                  R                  -   $ r7   )r:  r   r   r9   s    r;   r   Join._from_objects  s(    v		///$**2J2JJJr>   )r   r   r:  r   r   r+  r,  r7   r-  )(r@   rA   rB   rC   r]   r   r.   dp_clauseelement
dp_boolean_traverse_internalsr1  rC  classmethodrH  rK  rE   r   r   r?  r1   r   r  r   rs  rh   r@  r}  r  r  r  r3  r   deprecated_20r  r)  rL   r/  r   rF   __classcell__r   s   @r;   r   r     s*   & N 
"334	#445	&778	%001	"--. H6 C C2 =B39 39j 
 

" 
./
 0
$ %+ #B3
F ;?4 4l ! ! 	./6 0 6p  < 


$%$> 	"K
1 1 
./ 06 
!6
a@
a@F 
 

 K Kr>   r   c                       \ rS rSrS rSrg)NoIniti  c           	          [        SU R                  R                  < SU R                  R                  R                  5       < SU R                  R                  R                  5       < S35      e)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.)rW   r   r@   lowerr:   argr   s      r;   rC  NoInit.__init__  sO    ! ''''--/''--/

 
	
r>   r?   Nr@   rA   rB   rC   rC  rF   r?   r>   r;   r  r    s    
r>   r  c                      ^  \ rS rSrSrSrSrSrS\R                  4S\R                  4/r\S 5       r\SS j5       rSS	 jrU 4S
 jr\S 5       r\S 5       rS rS r\4U 4S jjr\S 5       r\S 5       rSrU =r$ )AliasedReturnsRowsi'  zHBase class of aliases against tables, subqueries, and other
selectables.TFelementrp   c                 L    U R                  U 5      nUR                  " U0 UD6  U$ r7   )__new___init)rG  r  r   rk  s       r;   rn   AliasedReturnsRows._construct5  s&    kk#		3"
r>   c                     [        5       e)z6Base factory method.  Subclasses need to provide this.rV   )rG  returnsrowsrp   s      r;   _factoryAliasedReturnsRows._factory;  s     "##r>   c                 d   [         R                  " [        R                  XS9U l        Xl        X l        Ucs  [        U[        5      (       a5  UR                  (       a$  [        USS 5      n[        U[        5      (       a  S n[        R                  " [        U 5      U=(       d    S5      nX l        g )Napply_propagate_attrsrp   anon)r   r   r   ReturnsRowsRoler  
_orig_namerh  r   r.  r   r"   safe_constructrN  rp   )r:   rS   rp   s      r;   r  AliasedReturnsRows._init@  s     ''!!:
 "<:z2200z648d$455D#222d8T^VLD	r>   c                 b   > [         [        U ]  U5        U R                  R                  U5        g r7   )rr  r  rh   r  ry  s     r;   rh   *AliasedReturnsRows._refresh_for_new_columnQ  s%     $?G,,V4r>   c                     U R                   n[        U[        5      (       a  Sn[        R                  (       a  U$ UR                  SS5      $ )Nanon_1asciibackslashreplace)rp   rh  r"   r1   py3kencodero   s     r;   r   AliasedReturnsRows.descriptionU  s<    yyd,--D99K;;w(:;;r>   c                     U R                   $ )z9Legacy for dialects that are referring to Alias.original.r  r9   s    r;   originalAliasedReturnsRows.original`  s     ||r>   c                 X    XR                   ;   a  gU R                  R                  U5      $ NT)r   r  r   r   s     r;   r   "AliasedReturnsRows.is_derived_frome  s&    )))||++J77r>   c                 :    U R                   R                  U 5        g r7   r  r  r9   s    r;   r  .AliasedReturnsRows._populate_column_collectionj  s    88>r>   c                    > U R                   n[        [        U ]  " SSU0UD6  X0R                   La  U R	                  5         g g )Nrq  r?   )r  rr  r  rs  r  )r:   rq  r   existing_elementr   s       r;   rs  "AliasedReturnsRows._copy_internalsm  sB    << $7JeJrJ <</))+ 0r>   c                     U /$ r7   r?   r9   s    r;   r    AliasedReturnsRows._from_objectsy  	    vr>   c                 .    U R                   R                  $ r7   )r  r  r9   s    r;   r  AliasedReturnsRows.bind}  s    ||   r>   )r  r  rp   r7   )r@   rA   rB   rC   r]   _is_from_containerr.  _supports_derived_columnsr.   r  dp_anon_namer  r  rn   r  r  rh   rE   r   r   r   r  r   rs  r   r  rF   r  r  s   @r;   r  r  '  s      % 
%667	"//0
  
 $ $"5 < <  8
? %+ 
,   ! !r>   r  c                   4    \ rS rSrSrSrSr\SS j5       rSr	g)	r   i  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`

rL   TNc                 d    [         R                  " [        R                  USS9R	                  X#S9$ )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)rp   r   )r   r   r   r   rL   )rG  rS   rp   r   s       r;   r  Alias._factory  s1    ^   *4

%T%
%	&r>   r?   r,  )
r@   rA   rB   rC   r]   r   rD   r  r  rF   r?   r>   r;   r   r     s%    " NM0& 0&r>   r   c                     ^  \ rS rSrSrSrSrSrSrSr	S\
R                  4S\
R                  4S\
R                  4S	\
R                  4S
\
R                  4/r   SU 4S jjr\R$                  S 5       rSS jrSS jrSS jrSrU =r$ )TableValuedAliasi  a  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  rp   _tableval_type_render_derived_render_derived_w_typesc                 t   > [         [        U ]  XS9  X@l        Uc  [        R
                  U l        g UU l        g r'  )rr  r  r  joins_implicitlyr	   r   r  )r:   rS   rp   table_value_typer  r   s        r;   r  TableValuedAlias._init  sF     	+J+B 0  '  	 " 	r>   c                 ,    [        X R                  5      $ )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  r9   s    r;   rg   TableValuedAlias.column  s    ( !':':;;r>   c                     [         R                  U UU R                  U R                  S9nU R                  (       a  SUl        U R
                  Ul        U$ )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.

rp   r  r  T)r  rn   r  r  r  r  r:   rp   tvas      r;   rL   TableValuedAlias.alias  sW     ))!00!22	 * 
 "&C*.*F*FC'
r>   c                 2    U R                  US9nSUl        U$ )zReturn a new :class:`_sql.TableValuedAlias` with the lateral flag
set, so that it renders as LATERAL.

.. seealso::

    :func:`_expression.lateral`

r(  T)rL   ra   r%  s      r;   rq   TableValuedAlias.lateral,  s      jjdj#
r>   c                     [         R                  U R                  UU R                  U R                  S9nSUl        X#l        U$ )av  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  rn   r  r  r  r  r  )r:   rp   
with_types	new_aliass       r;   render_derivedTableValuedAlias.render_derived9  sL    ` %//LL!00!22	 0 
	 %)	!,6)r>   )r  r  NNFr7   r,  )r@   rA   rB   rC   r]   r   r  r  r  r  r.   r  r  dp_typer  r  r  r   memoized_attributerg   rL   rq   r-  rF   r  r  s   @r;   r  r    s    * *N $O# 
%667	"//0	,445	-889	"$5$@$@A 
  ##< $<**8 8r>   r  c                   8    \ rS rSrSrSrSrSr\SS j5       r	Sr
g)	rm   it  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.

rq   TNc                 d    [         R                  " [        R                  USS9R	                  US9$ )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   rq   rG  rS   rp   s      r;   r  Lateral._factory  s0    ,   *

't'
	r>   r?   r7   )r@   rA   rB   rC   r]   r   ra   rD   r  r  rF   r?   r>   r;   rm   rm   t  s*    $ NKM r>   rm   c                      ^  \ rS rSrSrSr\R                  S\R                  4S\R                  4/-   r\
SS j5       r\R                  " S5      SU 4S jj5       rS	 rS
rU =r$ )r   i  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                 h    [         R                  " [        R                  U5      R	                  X#US9$ )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.

)rp   r   )r   r   r   r   r   )rG  rS   r   rp   r   s        r;   r  TableSample._factory  s6    X  4 4jAMMd N 
 	
r>   zsqlalchemy.sql.functionsc                    > [         R                  R                  n[        X%R                  5      (       d  UR
                  R                  U5      nX l        X@l        [        [        U ]/  XS9  g r'  )r1   rv   sql_functionsrh  Functionfuncsystemr   r   rr  r   r  )r:   rS   r   rp   r   	functionsr   s         r;   r  TableSample._init  sS    NN00	($6$677 ~~,,X6H 	k4&z&=r>   c                     U R                   $ r7   )r   r9   s    r;   _get_methodTableSample._get_method  s    }}r>   )r   r   r-  )r@   rA   rB   rC   r]   r   r  r  r.   r  r  r  r1   r   r  rB  rF   r  r  s   @r;   r   r     s     #N,@@	&778	"334D 
 -
 -
^ 
34> 5> r>   r   c                   2  ^  \ rS rSrSrSr\R                  S\R                  4S\R                  4S\R                  4S\R                  4/-   \R                  -   \R                  -   r\SS j5       r       SU 4S	 jjrS
 rSS jrS rS rS rSrU =r$ )CTEi  a)  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                 f    [         R                  " [        R                  U5      R	                  X#S9$ )zReturn a new :class:`_expression.CTE`,
or Common Table Expression instance.

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

)rp   rI  )r   r   r   
HasCTERolerF  )rG  rS   rp   rI  s       r;   r  CTE._factory$  s3      0 0*=AA B 
 	
r>   c	                    > X0l         X@l        XPl        X`l        U(       a  Xpl        U(       a  Xl        [        [        U ]#  XS9  g r'  )	rI  rJ  rG  rH  r   r   rr  rE  r  )
r:   rS   rp   rI  rJ  rG  rH  r   r   r   s
            r;   r  	CTE._init0  s;     #$"&N&Nc4z5r>   c                     U R                   b  U R                   R                  U 5        g U R                  R                  U 5        g r7   )rG  r  r  r9   s    r;   r  CTE._populate_column_collectionF  s0    ??&OO??ELL<<TBr>   c           
          [         R                  U R                  UU R                  U R                  U U R
                  U R                  S9$ )zReturn 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`

)rp   rI  rJ  rG  r   r   )rE  rn   r  rI  rJ  r   r   r   s      r;   rL   	CTE.aliasL  sC     ~~LLnnLLnnnn  
 	
r>   c           
          [         R                  U R                  R                  " U6 U R                  U R
                  U R                  U U R                  U R                  S9$ )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

rp   rI  rJ  rH  r   r   )	rE  rn   r  r   rp   rI  rJ  r   r   r   s     r;   r   	CTE.uniond  sR     ~~LL&nnLLnnnn  
 	
r>   c           
          [         R                  U R                  R                  " U6 U R                  U R
                  U R                  U U R                  U R                  S9$ )ab  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

rU  )	rE  rn   r  	union_allrp   rI  rJ  r   r   r   s     r;   rX  CTE.union_all}  sR     ~~LL""E*nnLLnnnn  
 	
r>   c                 8    U R                   b  U R                   $ U $ )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.
)rH  r9   s    r;   _get_reference_cteCTE._get_reference_cte  s     "&!;t~~EEr>   )rG  r   rH  r   rJ  rI  r,  )NFFNNNN)r@   rA   rB   rC   r]   r   r  r  r.   r  r  r   r   r   r   r  r  r  r  rL   r   rX  r[  rF   r  r  s   @r;   rE  rE    s    $ N 	..,==>+<<=+667)445	
	
 
6
6	7 
6
6	7  	
 	
 6,C
0
2
2F Fr>   rE  c                   T    \ rS rSrSrS\R                  4/rSr\	S 5       r
SS jrSrg)	HasCTEi  zLMixin that declares a class to include CTE support.

.. versionadded:: 1.1

_independent_ctesr?   c                 z    [         R                  " [        R                  U5      nU =R                  U4-  sl        g)a  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_  )r:   rF  s     r;   add_cteHasCTE.add_cte  s.    @ u43&(r>   Nc                 *    [         R                  XX#S9$ )a  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`.

)rp   rI  rJ  )rE  rn   )r:   rp   rI  rJ  s       r;   rF  
HasCTE.cte  s     \ ~~y  
 	
r>   r+  )r@   rA   rB   rC   r]   r.   dp_clauseelement_list_has_ctes_traverse_internalsr_  r   rb  rF  rF   r?   r>   r;   r^  r^    sC     
/EEF$  @) @)Dp
r>   r^  c                   p    \ rS rSrSrSrSrSr\SS j5       r	\
R                  " SS5      S	 5       rS
 rSrg)Subqueryi	  a1  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.

rK   TNc                 f    [         R                  " [        R                  U5      R	                  US9$ )z#Return a :class:`.Subquery` object.r(  )r   r   r   SelectStatementRolerK   r5  s      r;   r  Subquery._factory
  s.     %%z

((
	r>   rG   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                 \    U R                   R                  [        5      R                  5       $ r7   )r  r  r6  scalar_subqueryr9   s    r;   	as_scalarSubquery.as_scalar
  s#     ||++,<=MMOOr>   c                 f    [         R                  " SS5        U R                  R                  XX4SS9$ )NzExecuting a subquery object is deprecated and will raise ObjectNotExecutableError in an upcoming release.  Please execute the underlying select() statement directly.rG   T)_force)r1   warn_deprecatedr  _execute_on_connection)r:   
connectionmultiparamsparamsexecution_optionss        r;   rt  Subquery._execute_on_connection
  sB     	B 		
 ||22Vt 3 
 	
r>   r?   r7   )r@   rA   rB   rC   r]   r   _is_subqueryrD   r  r  r1   r   ro  rt  rF   r?   r>   r;   ri  ri  	  sV    8  NLM  
__	?	P	P
r>   ri  c                       \ rS rSrSrS\R                  4/rS rS r	\
S 5       r\
S 5       r\
S 5       rS	 rS
 rS r\
S 5       r\
S 5       rS rS rSrg)rT  i+
  z%Represent a grouping of a FROM clauser  c                 X    [         R                  " [        R                  U5      U l        g r7   )r   r   r   r   r  r:   r  s     r;   rC  FromGrouping.__init__0
  s     ''(<(<gFr>   c                     g r7   r?   r9   s    r;   r
  FromGrouping._init_collections3
      r>   c                 .    U R                   R                  $ r7   )r  r  r9   s    r;   r  FromGrouping.columns6
  s    ||###r>   c                 .    U R                   R                  $ r7   )r  r  r9   s    r;   r  FromGrouping.primary_key:
      ||'''r>   c                 .    U R                   R                  $ r7   )r  r  r9   s    r;   r  FromGrouping.foreign_keys>
      ||(((r>   c                 8    U R                   R                  U5      $ r7   )r  r   r}  s     r;   r   FromGrouping.is_derived_fromB
  s    ||++G44r>   c                 L    [        U R                  R                  " S0 UD65      $ Nr?   )rT  r  rL   r:   r   s     r;   rL   FromGrouping.aliasE
  s    DLL..4455r>   c                 L    [        U R                  R                  " S0 UD65      $ r  )rT  r  r)  r  s     r;   r)  "FromGrouping._anonymous_fromclauseH
  s    DLL>>DDEEr>   c                 .    U R                   R                  $ r7   )r  r/  r9   s    r;   r/  FromGrouping._hide_fromsK
  r  r>   c                 .    U R                   R                  $ r7   r  r   r9   s    r;   r   FromGrouping._from_objectsO
      ||)))r>   c                     SU R                   0$ Nr  r  r9   s    r;   __getstate__FromGrouping.__getstate__S
  s    4<<((r>   c                     US   U l         g r  r  )r:   states     r;   __setstate__FromGrouping.__setstate__V
  s    Y'r>   r  N)r@   rA   rB   rC   r]   r.   r  r  rC  r
  rE   r  r  r  r   rL   r)  r/  r   r  r  rF   r?   r>   r;   rT  rT  +
  s    /%'8'I'IJKG $ $ ( ( ) )56F ( ( * *)(r>   rT  c                   z  ^  \ rS rSrSrSrS\R                  4S\R                  4S\R                  4/r	Sr
Sr S	r U 4S
 jrS rS rS r\R$                  S 5       rS r\R*                  " S5      SS j5       r\R*                  " S5      SS j5       r\R*                  " S5      SS j5       r\S 5       rSrU =r$ )TableClauseiZ
  a  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.

ri  r  rp   r0  TFNc                   > [         [        U ]  5         Xl        [	        5       U l        [        5       U l        [        5       U l	        U H  nU R                  U5        M     UR                  SS5      nUb  XPl        U R                  b#  U R                  < SU R                  < 3U l        OU R                  U l        U(       a"  [        R                  " S[!        U5      -  5      eg)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.
r0  N.r   )rr  r  rC  rp   r   r   r   r  r  r  append_columnr   r0  fullnamer0   r   r  )r:   rp   r  r   r  r0  r   s         r;   rC  TableClause.__init__
  s    0 	k4)+	.0$;EAq!  $' K;;"'+{{DII>DM IIDM##$ADH$LMM r>   c                 l    U R                   b  U R                   S-   U R                  -   $ U R                  $ )Nr  )r0  rp   r9   s    r;   __str__TableClause.__str__
  s.    ;;";;$tyy0099r>   c                     g r7   r?   rf   s     r;   rh   #TableClause._refresh_for_new_column
  r  r>   c                     g r7   r?   r9   s    r;   r
  TableClause._init_collections
  r  r>   c                 |    [         R                  (       a  U R                  $ U R                  R                  SS5      $ )Nr  r  )r1   r  rp   r  r9   s    r;   r   TableClause.description
  s+    999999##G-?@@r>   c                     UR                   nUb-  X0La)  [        R                  " SUR                  < SU< S35      eU R                  R                  U5        Xl         g )Nzcolumn object 'z' already assigned to table '')ri  r0   r   r  r   add)r:   r  r   existings       r;   r  TableClause.append_column
  sP    77H$8##55($ 
 	!r>   zsqlalchemy.sql.dmlc                 \    [         R                  R                  R                  " U 4XS.UD6$ )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.

)r  inline)r1   rv   sql_dmlInsert)r:   r  r  rN   s       r;   insertTableClause.insert
  s4     ~~%%,,

28
 	
r>   c                 `    [         R                  R                  R                  " U 4UUUS.UD6$ )zGenerate 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   r  r  )r1   rv   r  Update)r:   r   r  r  rN   s        r;   r`  TableClause.update
  s<     ~~%%,,
#	

 
 	
r>   c                 X    [         R                  R                  R                  " X40 UD6$ )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   rv   r  Deleter   s      r;   deleteTableClause.delete
  s$     ~~%%,,TI&IIr>   c                     U /$ r7   r?   r9   s    r;   r   TableClause._from_objects  r  r>   )r   r  r  rp   r  r0  r,  r/  r7   )r@   rA   rB   rC   r]   r   r.   )dp_fromclause_canonical_column_collection	dp_stringr  r.  implicit_returning_autoincrement_columnrC  r  rh   r
  r1   r4  r   r  r   r  r`  r  rE   r   rF   r  r  s   @r;   r  r  Z
  s   : N GG	
 
",,-	$../ = !>(NT 
A A	 
-.
 /
 
-.
 /
& 
-.J /J  r>   r  c                       \ rS rSrS\R
                  4S\R                  4S\R                  4S\R                  4S\R                  4/r\S 5       r	S r
S	 rS
 r     SS jrSrg)ForUpdateArgi  ofnowaitreadskip_locked	key_sharec                 r    [        U[        5      (       a  U$ US;   a  g USL a
  [        5       $ [        S0 UD6$ )Nr,  Tr?   )rh  r  )rG  with_for_updates     r;   _from_argumentForUpdateArg._from_argument  s>    o|44""-$>!2/22r>   c                 `   [        U[        5      =(       a    UR                  U R                  :H  =(       ax    UR                  U R                  :H  =(       aX    UR                  U R                  :H  =(       a8    UR
                  U R
                  :H  =(       a    UR                  U R                  L $ r7   )rh  r  r  r  r  r  r  r   s     r;   __eq__ForUpdateArg.__eq__   s    ul+ $+$

dii'$ !!T%5%55$ 4>>1	$
 DGG#	
r>   c                 .    U R                  U5      (       + $ r7   )r  r   s     r;   __ne__ForUpdateArg.__ne__*  s    ;;u%%%r>   c                     [        U 5      $ r7   )rN  r9   s    r;   __hash__ForUpdateArg.__hash__-  s    $xr>   Nc                     Xl         X l        X@l        XPl        UbP  [        R
                  " U5       Vs/ s H(  n[        R                  " [        R                  U5      PM*     snU l
        gSU l
        gs  snf )zJRepresents arguments specified to
:meth:`_expression.Select.for_update`.

N)r  r  r  r  r1   to_listr   r   r   ColumnsClauseRoler  )r:   r  r  r  r  r  elems          r;   rC  ForUpdateArg.__init__0  si     	&"> !LL,,D   !8!8$?,DG
 DGs   /A4)r  r  r  r  r  FFNFF)r@   rA   rB   rC   r.   rf  r  r  r  r  r  r  r  rC  rF   r?   r>   r;   r  r    s    	 667	$//0	"--.	)445	'223 3 3
&
 r>   r  c                      ^  \ rS rSrSrSrSrSrS\R                  4S\R                  4S\R                  4S	\R                  4/rU 4S
 jr\S 5       r\S 5       r\SS j5       r\S 5       rS r\S 5       rSrU =r$ )ValuesiJ  zRepresent 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

Tr  r?   _column_args_datarp   literal_bindsc                    > [         [        U ]  5         Xl        UR	                  SS5      U l        UR	                  SS5      U l        U R
                  SLU l        g)aC  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.

rp   Nr  F)rr  r  rC  r  r   rp   r  r.  )r:   r  r   r   s      r;   rC  Values.__init__a  sO    H 	fd$&#FF64(	VVOU;!%$!6r>   c                 X    U R                    Vs/ s H  oR                  PM     sn$ s  snf r7   )r  type)r:   r   s     r;   _column_typesValues._column_types  s$    $($5$56$5S$5666s   'c                 6    Xl         U R                   SLU l        g)a  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)rp   r.  )r:   rp   r   s      r;   rL   Values.alias  s      	!%$!6r>   c                 &    SU l         Ub  Xl        gg)zReturn a new :class:`_expression.Values` with the lateral flag set,
so that
it renders as LATERAL.

.. seealso::

    :func:`_expression.lateral`

TN)ra   rp   ro   s     r;   rq   Values.lateral  s      I r>   c                 0    U =R                   U4-  sl         g)a2  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)r  )r:   r  s     r;   dataValues.data  s      	

vi
r>   c                 l    U R                    H$  nU R                  R                  U5        Xl        M&     g r7   )r  r   r  ri  )r:   r  s     r;   r  "Values._populate_column_collection  s)    ""AMMa G #r>   c                     U /$ r7   r?   r9   s    r;   r   Values._from_objects  r  r>   )r  ra   r  rp   r.  r7   )r@   rA   rB   rC   r]   r.  r   r  r.   rf  dp_dml_multi_valuesr  r  r  rC  rE   r  r   rL   rq   r  r  r   rF   r  r  s   @r;   r  r  J  s     NE 
*@@A	#778	",,-	+667	(7T 7 7 7 7$      "
  r>   r  c                   v   \ rS rSrSrSrSrS rS r\	S 5       r
\	S 5       r\	S 5       r\	\R                  " S	S
5      S 5       5       r\	S 5       r\R                  " S	S5      S 5       r\R&                  S 5       r\R                  " S	S5      S 5       rS rS rS rSS jr\	S 5       rSS jrS rSS jrSrg)
SelectBasei  zBase class for SELECT statements.


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


Tc                     [        5       er7   rV   r   s     r;   r  .SelectBase._generate_fromclause_column_proxies  rj   r>   c                 $    U R                  5         g r7   )rt  rf   s     r;   rh   "SelectBase._refresh_for_new_column  s      "r>   c                     [        5       e)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

rV   r9   s    r;   selected_columnsSelectBase.selected_columns  s    8 "##r>   c                     [        5       e)zA 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`

rV   r9   s    r;   rX    SelectBase._all_selected_columns  s     "##r>   c                     U R                   $ )a  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`


)r   r9   s    r;   r[   SelectBase.exported_columns  s    . $$$r>   rG   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                 .    U R                   R                  $ r7   )_implicit_subqueryr  r9   s    r;   r  SelectBase.c0  s     &&...r>   c                     U R                   $ r7   )r  r9   s    r;   r  SelectBase.columnsA  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                 :    U R                   R                  " U0 UD6$ r7   )r  r   r  s      r;   r   SelectBase.selectE  s      &&--s9b99r>   c                 "    U R                  5       $ r7   rK   r9   s    r;   r  SelectBase._implicit_subqueryQ  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                 "    U R                  5       $ r7   )rn  r9   s    r;   ro  SelectBase.as_scalarU  s     ##%%r>   c                     [        U 5      $ )a)  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

)Existsr9   s    r;   existsSelectBase.exists_  s     d|r>   c                 h    U R                   [        La  U R                  [        5      n [        U 5      $ )a  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_styler6  r  ScalarSelectr9   s    r;   rn  SelectBase.scalar_subqueryp  s/    0 $44''(89DD!!r>   c                 @    U R                  5       R                  U5      $ )zReturn a 'scalar' representation of this selectable, embedded as a
subquery with a label.

.. seealso::

    :meth:`_expression.SelectBase.as_scalar`.

)rn  labelro   s     r;   r  SelectBase.label  s     ##%++D11r>   Nc                 ,    [         R                  X5      $ rl   )rm   r  ro   s     r;   rq   SelectBase.lateral  s     ++r>   c                     U /$ r7   r?   r9   s    r;   r   SelectBase._from_objects  r  r>   c                 J    [         R                  U R                  5       U5      $ )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

)ri  rn   _ensure_disambiguated_namesro   s     r;   rK   SelectBase.subquery  s!    P ""4#C#C#EtLLr>   c                     [        5       e)zdEnsure that the names generated by this selectbase will be
disambiguated in some way, if possible.

rV   r9   s    r;   r"  &SelectBase._ensure_disambiguated_names  s     "##r>   c                      U R                  US9$ )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;   rL   SelectBase.alias  s     }}$}''r>   r?   r7   r,  )r@   rA   rB   rC   r]   r`   	is_selectr  rh   rE   r   rX   r[   r1   r   r  r  r   r   r1  r  ro  r  rn  r  rq   r   rK   r"  rL   rF   r?   r>   r;   r  r    s8     I$# $ $: $ $ % %0 	__		/ /   
__	2:: ## $ 
__	:&&"":	2,  (MT$(r>   r  c                       \ rS rSrSrSrS\R                  4/rSr	S r
S rS rS	 r\S
 5       r\S 5       rSS jrS rS rS r\S 5       r\S 5       r\S 5       rSrg)SelectStatementGroupingi  zRepresent 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                 X    [         R                  " [        R                  U5      U l        g r7   )r   r   r   rk  r  r}  s     r;   rC   SelectStatementGrouping.__init__  s     ''(A(A7Kr>   c                 l    U R                   R                  5       nXR                   La  [        U5      $ U $ r7   )r  r"  r*  )r:   new_elements     r;   r"  3SelectStatementGrouping._ensure_disambiguated_names   s.    ll>>@ll**;77Kr>   c                     U R                   $ r7   r  r9   s    r;   get_label_style'SelectStatementGrouping.get_label_style  s       r>   c                 J    [        U R                  R                  U5      5      $ r7   )r*  r  r  )r:   label_styles     r;   r  'SelectStatementGrouping.set_label_style
  s!    &LL((5
 	
r>   c                 .    U R                   R                  $ r7   )r  r  r9   s    r;   r  $SelectStatementGrouping._label_style  r  r>   c                     U R                   $ r7   r  r9   s    r;   select_statement(SelectStatementGrouping.select_statement  s    ||r>   Nc                     U $ r7   r?   rU  s     r;   r?  "SelectStatementGrouping.self_group      r>   c                 8    U R                   R                  U5      $ r7   )r  _generate_columns_plus_names)r:   anon_for_dupe_keys     r;   rA  4SelectStatementGrouping._generate_columns_plus_names  s    ||889JKKr>   c                 :    U R                   R                  U5        g r7   r  )r:   rK   s     r;   r  ;SelectStatementGrouping._generate_fromclause_column_proxies  s    88Br>   c                 8    U R                   R                  U5      $ r7   )r  _generate_proxy_for_new_column)r:   rg   rK   s      r;   rG  6SelectStatementGrouping._generate_proxy_for_new_column   s    ||::8DDr>   c                 .    U R                   R                  $ r7   )r  rX   r9   s    r;   rX   -SelectStatementGrouping._all_selected_columns#  s    ||111r>   c                 .    U R                   R                  $ )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  r   r9   s    r;   r   (SelectStatementGrouping.selected_columns'  s     ||,,,r>   c                 .    U R                   R                  $ r7   r  r9   s    r;   r   %SelectStatementGrouping._from_objects7  r  r>   r  r7   )r@   rA   rB   rC   r]   r   r.   r  r  _is_select_containerrC  r"  r3  r  rE   r  r;  r?  rA  r  rG  rX   r   r   rF   r?   r>   r;   r*  r*    s     1N%'8'I'IJKL!

 ) )  LCE 2 2 - - * *r>   r*  c                   |    \ rS rSrSr\R                  " SS5      S 5       r\R                  " SS5      S 5       rSr	g	)
DeprecatedSelectBaseGenerationsi<  zA collection of methods available on :class:`_sql.Select` and
:class:`_sql.CompoundSelect`, these are all **deprecated** methods as they
modify the object in-place.

rG   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                 >    U R                   R                  " U /UQ76   g)al  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r:   clausess     r;   append_order_by/DeprecatedSelectBaseGenerations.append_order_byC  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                 >    U R                   R                  " U /UQ76   g)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_byrT  rU  s     r;   append_group_by/DeprecatedSelectBaseGenerations.append_group_by[  s    & 	$$T4G4r>   r?   N)
r@   rA   rB   rC   r]   r1   r   rW  r[  rF   r?   r>   r;   rQ  rQ  <  sQ     
__	955" 
__	955r>   rQ  c                      \ rS rSrSrSrSrSrSrSr	Sr
Sr\R                  " SS9\SSSSSS4S j5       r\     S S	 j5       rS
 rS r\R(                  " SSS9S 5       r\S 5       r\S 5       rS!S jrS r\S 5       rS r\S 5       r\S 5       r\S 5       r\S"S j5       r \S 5       r!\\RD                  " S5      S 5       5       r#\S 5       r$\S 5       r%Sr&g)#GenerativeSelectiq  a  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.

r?   N)r   z^The :paramref:`_sql.select.bind` argument is deprecated and will be removed in SQLAlchemy 2.0.)r  Fc                    U(       a0  [         R                  (       a  [         R                  " SSS9  [        nXl        Ub  U R
                  R                  X5        Ub  U R                  R                  X5        Ub1  U R                  R                  " U /[         R                  " U5      Q76   Ub1  U R                  R                  " U /[         R                  " U5      Q76   Xpl        g )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_20r7  r  limitrT  offsetrS  r  rZ  _bind)r:   r  
use_labelsre  rf  rS  rZ  r  s           r;   rC  GenerativeSelect.__init__  s    " &&''E
  ! :L(JJ%%d2KK&&t4MM((GX0FGMM((GX0FG
r>   c                 (    [        UUUUUS9U l        g)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.

)r  r  r  r  r  N)r  _for_update_arg)r:   r  r  r  r  r  s         r;   r   GenerativeSelect.with_for_update  s!    l  ,# 
r>   c                     U R                   $ )z;
Retrieve the current label style.

.. versionadded:: 1.4

r2  r9   s    r;   r3   GenerativeSelect.get_label_style  s        r>   c                 P    U R                   ULa  U R                  5       n Xl         U $ )ag  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_DISAMBIGUATE_ONLY`.

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r:   styles     r;   r   GenerativeSelect.set_label_style  s*    L E)>>#D %r>   z*:meth:`_sql.GenerativeSelect.apply_labels`z<Use set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL) instead.r  c                 ,    U R                  [        5      $ r7   )r  r7  r9   s    r;   apply_labelsGenerativeSelect.apply_labels&  s     ##$BCCr>   c                 `    [         R                  " [        R                  U R                  5      $ )z9ClauseList access to group_by_clauses for legacy dialects)r'   _construct_rawr   comma_op_group_by_clausesr9   s    r;   _group_by_clause!GenerativeSelect._group_by_clause.  (     (( 6 6
 	
r>   c                 `    [         R                  " [        R                  U R                  5      $ )z9ClauseList access to order_by_clauses for legacy dialects)r'   rx  r   ry  _order_by_clausesr9   s    r;   _order_by_clause!GenerativeSelect._order_by_clause5  r}  r>   c                 J    [         R                  " [        R                  XUS9$ )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.

)rp   type_)r   r   r   LimitOffsetRole)r:   r  rp   r  s       r;   _offset_or_limit_clause(GenerativeSelect._offset_or_limit_clause<  s$     !!7U
 	
r>   c                     Uc  g UR                   n[        R                  " U5      $ ! [         a6  n[        R                  " [
        R                  " SU-  5      US9   SnAgSnAff = f)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)r:   clauseattrnamevalueerrs        r;   _offset_or_limit_clause_asint.GenerativeSelect._offset_or_limit_clause_asintG  sk     >	%..E ::e$$  	KK  +-56 !$	s   ( 
A(,A##A(c                 :    U R                  U R                  S5      $ )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.

re  )r  _limit_clauser9   s    r;   _limitGenerativeSelect._limit^  s     11$2D2DgNNr>   c                 "    [        U[        5      $ )z[True if the clause is a simple integer, False
if it is not present or is a SQL expression.
)rh  r4   r:   r  s     r;   _simple_int_clause#GenerativeSelect._simple_int_clauseh  s     &"344r>   c                 :    U R                  U R                  S5      $ )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.

rf  )r  _offset_clauser9   s    r;   _offsetGenerativeSelect._offsetn  s"     11
 	
r>   c                 r    U R                   S L=(       d#    U R                  S L=(       d    U R                  S L$ r7   )r  r  _fetch_clauser9   s    r;   _has_row_limiting_clause)GenerativeSelect._has_row_limiting_clausez  s=     d* .""$..!!-	
r>   c                 L    S=U l         U l        U R                  U5      U l        g)a  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  )r:   re  s     r;   re  GenerativeSelect.limit  s'    : ;?>T7!99%@r>   c                 v    SU l         Uc  S=U l        U l        gU R                  U5      U l        UUS.U l        g)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  )r:   countr  r  s       r;   fetchGenerativeSelect.fetch  sE    P "=>BBD!;!%!=!=e!DD&"*D&r>   c                 0    U R                  U5      U l        g)aa  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  )r:   rf  s     r;   rf  GenerativeSelect.offset  s    4 #::6Br>   rt   c                     [         R                  R                  nS=U l        U l        UR                  U R                  U R                  X5      u  U l        U l        g)ab  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   rv   rw   r  r  _make_slicer  r  )r:   startstoprw   s       r;   sliceGenerativeSelect.slice  sR    R >>**:>>T72:2F2F 3 3U3
/D/r>   c                     [        U5      S:X  a  US   c  SU l        gU =R                  [        S U 5       5      -  sl        g)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   Nr?   c              3   l   #    U  H*  n[         R                  " [        R                  U5      v   M,     g 7fr7   )r   r   r   OrderByRoler   r  s     r;   r   ,GenerativeSelect.order_by.<locals>.<genexpr>?  -      ,%F   !2!2F;;%   24)r  r  r   rU  s     r;   rS  GenerativeSelect.order_by  sF    : w<1!3%'D"""e ,%, ' "r>   c                     [        U5      S:X  a  US   c  SU l        gU =R                  [        S U 5       5      -  sl        g)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   Nr?   c              3   l   #    U  H*  n[         R                  " [        R                  U5      v   M,     g 7fr7   )r   r   r   GroupByRoler  s     r;   r   ,GenerativeSelect.group_by.<locals>.<genexpr>`  r  r  )r  rz  r   rU  s     r;   rZ  GenerativeSelect.group_byD  sF    2 w<1!3%'D"""e ,%, ' "r>   )	rg  r  r  rk  rz  r  r  r  r  r  r-  )FF)'r@   rA   rB   rC   r]   r  rz  r  r  r  r  rk  r1   r3  LABEL_STYLE_DEFAULTrC  r   r  r3  r  r  ru  rE   r{  r  r  r  r  r  r  r  re  r  rf  r   r  rS  rZ  rF   r?   r>   r;   r^  r^  q  s    MNM O	
 )""H  ;
 ;
z!)V 
4
D
D 
 
 
 
	
%. O O5 	
 	
 
 
 A A> / /b C C6 	./+
 0 +
Z " "H  r>   r^  defaultcompound_selectc                   8    \ rS rSr\R
                  S 5       rSrg)CompoundSelectStateif  c                     U R                   R                  5       nSUl        [        S UR                   5       5      nX"U4$ )NFc              3   <   #    U  H  oR                   U4v   M     g 7fr7   r  rY  s     r;   r   :CompoundSelectState._label_resolve_dict.<locals>.<genexpr>m  s     6%5%%%5r]  )	statementrK   r.  dictr  )r:   hacky_subqueryds      r;   _label_resolve_dict'CompoundSelectState._label_resolve_dicth  s=     002+0(6^%5%566Qwr>   r?   N)r@   rA   rB   rC   r1   r4  r  rF   r?   r>   r;   r  r  f  s    	 r>   r  c            
          ^  \ rS rSrSrSrS\R                  4S\R                  4S\R                  4S\R                  4S\R                  4S	\R                  4S
\R                  4S\R                  4S\R                  4/	\R                  -   r\R                  " S5      r\R                  " S5      r\R                  " S5      r\R                  " S5      r\R                  " S5      r\R                  " S5      rSrS r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rS rS+S jr S r!S r"S r#S  r$U 4S! jr%\&S" 5       r'\&S# 5       r(\&\RR                  " S$S%S&S'9S( 5       5       r*\*RV                  S) 5       r*S*r,U =r-$ ),CompoundSelectiq  a4  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  rz  rk  keywordUNIONz	UNION ALLEXCEPTz
EXCEPT ALL	INTERSECTzINTERSECT ALLTc                 h   UR                  SS5      U l        Xl        U Vs/ s H5  n[        R                  " [
        R                  U5      R                  U S9PM7     snU l        U(       a*  [        R                  (       a  [        R                  " SSS9  [        R                  " U 40 UD6  g s  snf )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`  ra  )r   _auto_correlater  r   r   r   CompoundElementRoler?  r  r1   rc  rd  r^  rC  )r:   r  r  rN   ss        r;   rC  CompoundSelect.__init__  s    %zz+u=
 	
  U66:EE F  	
 d--##C
  	!!$1&1#
s   <B/c                 <    [        [         R                  /UQ70 UD6$ )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  rG  r  rN   s      r;   _create_unionCompoundSelect._create_union  s    $ n22GWGGGr>   c                 <    [        [         R                  /UQ70 UD6$ )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_all CompoundSelect._create_union_all  s    $ n66KKFKKr>   c                 <    [        [         R                  /UQ70 UD6$ )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_exceptCompoundSelect._create_except  s     n33HgHHHr>   c                 <    [        [         R                  /UQ70 UD6$ )a!  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_all!CompoundSelect._create_except_all  s     n77L'LVLLr>   c                 <    [        [         R                  /UQ70 UD6$ )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_intersect CompoundSelect._create_intersect  s     n66KKFKKr>   c                 <    [        [         R                  /UQ70 UD6$ )a$  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_all$CompoundSelect._create_intersect_all  s     n::OWOOOr>   c                 <    U R                   S   R                  5       $ Nr   )r  _scalar_typer9   s    r;   r  CompoundSelect._scalar_type  s    ||A++--r>   c                     [        U 5      $ r7   )r*  rU  s     r;   r?  CompoundSelect.self_group"  s    &t,,r>   c                 Z    U R                    H  nUR                  U5      (       d  M    g   gNTF)r  r   )r:   r   r  s      r;   r   CompoundSelect.is_derived_from%  s)    A  ,,  r>   c                     U R                   ULaF  U R                  5       n U R                  S   R                  U5      nU/U R                  SS  -   U l        U $ Nr   r   )r  rp  r  _set_label_style)r:   rr  select_0s      r;   r  CompoundSelect._set_label_style+  sR    E)>>#D||A77>H$:QR(88DLr>   c                     U R                   S   R                  5       nXR                   S   La(  U R                  5       n U/U R                   SS  -   U l         U $ r  )r  r"  rp  )r:   
new_selects     r;   r"  *CompoundSelect._ensure_disambiguated_names3  sP    \\!_@@B
\\!_,>>#D&<$,,qr*::DLr>   c           
         U R                   S   nU R                  [        La  UR                  U R                  5      nUR	                  U5        [        UR                  R                  [        U R                    Vs/ s H  o3R                  PM     sn6 5       H>  u  pE[        U5       VVs/ s H  u  pgUR                  SUS-   05      PM     snnUl        M@     g s  snf s  snnf )Nr   weightr   )r  r  r  r  r  zipr  _all_columnsr   	enumerate	_annotate_proxies)r:   rK   r  r  subq_colselect_colsir  s           r;   r  2CompoundSelect._generate_fromclause_column_proxies;  s     <<?$77//0A0ABH44X> &)JJ##dll;l$$l;<&
!H (4!4FQ Xq1u-.4!H	&
;!s   <C,"C!c                 t   > [         [        U ]  U5        U R                   H  nUR                  U5        M     g r7   )rr  r  rh   r  )r:   rg   r   r   s      r;   rh   &CompoundSelect._refresh_for_new_column[  s.    nd;FCllF**62 #r>   c                 4    U R                   S   R                  $ r  )r  rX   r9   s    r;   rX   $CompoundSelect._all_selected_columns`  s    ||A444r>   c                 4    U R                   S   R                  $ )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  r   r9   s    r;   r   CompoundSelect.selected_columnsd  s    ( ||A///r>   r  r  Fr  c                     U R                   (       a  U R                   $ U R                   H  nUR                  nU(       d  M  Us  $    g)Returns the :class:`_engine.Engine` or :class:`_engine.Connection`
to which this :class:`.Executable` is bound, or None if none found.

N)rg  r  r  )r:   r  es      r;   r  CompoundSelect.bindz  s;     ::::AAq 
 r>   c                     Xl         g r7   rg  r:   r  s     r;   r  r        
r>   )r  rg  r  r  r7   ).r@   rA   rB   rC   r]   r   r.   rf  r  dp_plain_dictr  r   %_clone_annotations_traverse_internalsr  r1   symbolr  r  r  r  r  r  r  rC  r  r  r  r  r  r  r  r  r?  r   r  r"  r  rh   rE   rX   r   r  r  setterrF   r  r  s   @r;   r  r  q  s*   ( 'N 
%;;<	+<<=	,==>	+<<=	 "3"A"AB	/EEF	/EEF	->>?	%//0
 	!FF
G KK EK(I[["F\*JK(IKK0M2, H H& L L& I I  M M  L L  P P .-@3
 5 5 0 0* 	"K
  
[[ r>   r  c                   D   \ rS rSrSr\R                  " SS5      S 5       r\R                  " SS5      S 5       r\R                  " SS5      S	 5       r	\R                  " SS
5      S 5       r
\R                  " SS5      S 5       r\R                  " SS5      S 5       rSrg)DeprecatedSelectGenerationsi  zA collection of methods available on :class:`_sql.Select`, these
are all **deprecated** methods as they modify the :class:`_sql.Select`
object in -place.

rG   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                 :    U R                   R                  X5        g)zAppend 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  rT  r   s     r;   append_correlation.DeprecatedSelectGenerations.append_correlation  s    $ 	%%d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                 :    U R                   R                  X5        g)a/  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_columnsrT  rf   s     r;   r  )DeprecatedSelectGenerations.append_column  s    ( 	''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                 :    U R                   R                  X5        g)zAppend 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   rT  r  s     r;   append_prefix)DeprecatedSelectGenerations.append_prefix  s      	''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                 :    U R                   R                  X5        g)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)whererT  )r:   r   s     r;   append_whereclause.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                 :    U R                   R                  X5        g)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)havingrT  r:   r/  s     r;   append_having)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                 :    U R                   R                  X5        g)a  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  rT  r   s     r;   append_from'DeprecatedSelectGenerations.append_from   s      	''9r>   r?   N)r@   rA   rB   rC   r]   r1   r   r"  r  r(  r,  r1  r4  rF   r?   r>   r;   r   r     s     
__	788 
__	966  
__	9
6
6 
__	355 
__	411 
__	9
:
:r>   r   r   c                   6   \ rS rSrSr " S S\5      rS r\S 5       r	\S 5       r
\S 5       r\S	 5       r\S
 5       rS r\SS j5       r SS jrS r\S 5       r\S 5       rS r\R,                  " S5      S 5       r\R,                  " S5      S 5       rSrg)SelectStatei  )from_clausesfromscolumns_plus_namesr  c                       \ rS rSr/ rSrg)*SelectState.default_select_compile_optionsi  r?   N)r@   rA   rB   rC   _cache_key_traversalrF   r?   r>   r;   default_select_compile_optionsr<    s    !r>   r>  c                 j   Xl         UR                  U l        UR                   H)  nU R	                  UR                  UR
                  5        M+     UR                  (       a&  U R	                  UR                  UR
                  5        U R                  U5      U l        UR                  S5      U l	        g r  )
r  	_from_objr8  _memoized_select_entities_setup_joins_raw_columns
_get_fromsr9  rA  r:  )r:   r  compilerr   memoized_entitiess        r;   rC  SelectState.__init__  s    "%//!*!D!D!..0A0N0N "E
 !!i44i6L6LM__Y/
"+"H"H"Nr>   c                     [        S5      e)NzLThe default SELECT construct without plugins does not implement this method.rV   )rG  s    r;   _plugin_not_implemented#SelectState._plugin_not_implemented/  s    !%
 	
r>   c           
          UR                  S5       VVVs/ s H  u  p#p$nUUR                  US.PM     snnn$ s  snnnf )NF)rp   r  r   )rA  r  )rG  r  _rp   r  s        r;   get_column_descriptions#SelectState.get_column_descriptions6  sP     66u=	
 > 'Q	  >	
 		
 	
s   9c                 $    U R                  5         g r7   )rI  )rG  r  from_statements      r;   rP  SelectState.from_statementC  s    ##%r>   c                     U R                  [        R                  R                  S UR                   5       5      5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7fr7   r   )r   r  s     r;   r   7SelectState.get_columns_clause_froms.<locals>.<genexpr>J  s      *5K'%%5Kr  )_normalize_fromsra  rb  from_iterablerC  )rG  r  s     r;   get_columns_clause_froms$SelectState.get_columns_clause_fromsG  s:    ##OO)) *5>5K5K* 
 	
r>   c                 l   ^^^^ U[         L mU[        Lm[        5       m[        5       mSUUUU4S jjnU$ )Nc                 z  > U R                   (       a  g T(       d  U R                  nUc  SnU$ T(       a  U R                  OU R                  nUc/  SnUT;   a  U R                  U5      T-  $ TR	                  U5        U$ UT;   a%  T(       a  U R
                  T-  $ U R                  T-  $ TR	                  U5        U$ )N	_no_label)_is_text_clause
_proxy_keyr\  _anon_labelr  _anon_tq_key_label_anon_key_label)r  col_namerp   r  namespatable_qualifieds      r;   go1SelectState._column_naming_convention.<locals>.goX  s      ||<&D&51??1<<D|"5===.33IIdOK ' ((2- **R/ 		$r>   r7   )r7  r6  r    r  )rG  r6  re  r  rb  rc  rd  s      @@@@r;   _column_naming_convention%SelectState._column_naming_conventionO  s;     &)GG$44	 	< 	r>   c                 ~   U R                  [        R                  " [        R                  R                  UR                   Vs/ s H  nUR
                  PM     sn5      [        R                  R                  UR                   Vs/ s H  nUR
                  PM     sn5      U R                  5      US9$ s  snf s  snf )N)check_statement)rU  ra  rb  rV  rC  r   _where_criteriar8  )r:   r  r  s      r;   rD  SelectState._get_fromsx  s    $$OO-- (1'='='=G  --'= -- (1'@'@'@G  --'@ !! &! % 
 	
s   B5B:Nc           
      2   [        5       n/ nU H  nUR                  (       a%  UR                  UL a  [        R                  " S5      eUR                  UR                  5      (       a  M[  UR                  U5        UR                  UR                  5        M     U(       al  [        [        R                  R                  U Vs/ s H  n[        UR                  5      PM     sn5      5      nU(       a  U Vs/ s H  ofU;  d  M
  UPM     nnU$ s  snf s  snf )a  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  rz  r  r0   InvalidRequestErrorr   r   r  r`  ra  rb  rV  r   r/  )rG  iterable_of_fromsrj  seenr9  itemrv  toremoves           r;   rU  SelectState._normalize_froms  s     u%D  T\\_%D--C  $$T%5%566T"D,,- & --<ABEq^AMM2EBH
  %*?Eqh->E? C @s   D8	DDc                    U R                   nU R                  R                  (       aS  U R                  R                  nU(       a6  U Vs/ s H)  nU[        [        X1=(       d    S5      U5      ;  d  M'  UPM+     nnU R                  R                  bJ  U Vs/ s H=  nU[        [        X1=(       d    S5      U R                  R                  5      ;  d  M;  UPM?     nnU R                  R                  (       al  U(       ae  [        U5      S:  aV  U Vs/ s H  nU[        X25      ;  d  M  UPM     nn[        U5      (       d#  [        R                  " SU R                  -  5      eU$ s  snf s  snf s  snf )zReturn 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.

r?   r   zSelect statement '%r' returned no FROM clauses due to auto-correlation; specify correlate(<tables>) to control correlation manually.)
r9  r  
_correlater   _correlate_exceptr   r  r  r0   ro  )r:   explicit_correlate_fromsimplicit_correlate_fromsr9  to_correlaterv  s         r;   _get_display_fromsSelectState._get_display_froms  sn    

>>$$>>44L #
"/,!#Ar %	 "  
 >>++7 
A)(=2 NN44	   
 NN**(E
Q
 A+ELM    u::-- 
 #'..1  c

$s$   	&E%3E%:E*E*E/(E/c                    [        S U R                  R                   5       5      n[        S [        U R                  5       5       5      nUR                  5       nUR                  5        H  u  pEUR                  XE5        M     XU4$ )Nc              3      #    U  H9  nUR                   (       d  M  UR                  =(       d    UR                  U4v   M;     g 7fr7   )_allow_label_resolve	_tq_labelr  rY  s     r;   r   ASelectState._memoized_attr__label_resolve_dict.<locals>.<genexpr>  s4      
9%% &Q[[!AEE1%9s
   A(Ac              3   d   #    U  H&  nUR                   (       d  M  UR                  U4v   M(     g 7fr7   )r  r  rY  s     r;   r   r    s*      
2%% QUUAJ2s   00)r  r  rX   r   r9  copyitems
setdefault)r:   	with_cols
only_froms	only_colsr  r  s         r;   "_memoized_attr__label_resolve_dict.SelectState._memoized_attr__label_resolve_dict  s     
^^99
 
	
  
&tzz2
 


 NN$	$**,JC  , - i//r>   c                 J    UR                   (       a  UR                   S   S   $ g )Nr   )rB  )rG  stmts     r;   determine_last_joined_entity(SelectState.determine_last_joined_entity  s$    $$R(++r>   c                 V    [        UR                  5       Vs/ s H  o"PM     sn$ s  snf r7   )r   rC  )rG  r  r  s      r;   all_selected_columns SelectState.all_selected_columns  s'    ,Y-C-CDEDaDEEEs   &c           
      T   U H  u  p4pVUS   nUS   nUc  U R                  X%X45      u  nn	OU R                  U5      n	U	bG  U R                  U	   n
U R                  S U	 [        U
UUUUS94-   U R                  U	S-   S  -   U l        M  U R                  [        XSXGUS94-   U l        M     g )Nr   r   rF  r   )"_join_determine_implicit_left_side_join_place_explicit_left_sider8  r   )r:   rM   raw_columnsr   r   r:  flagsr   r   replace_from_obj_indexleft_clauses              r;   rB  SelectState._setup_joins  s    .2*UdI&G=D| ;;u*
 ,0+N+N,' &1 #//0FG %%&='=>'!$$+!%	 ''(>(B(DE
F ! %)$5$5hdK9 %!I /3r>   rt   c           	      2   [         R                  R                  nSnU R                  nU(       a+  UR	                  XsU5      n[        U5      S:X  a	  US   nXv   nO0 n	U R                  n
[        R                  " [        R                  R                  U Vs/ s H  oR                  PM     sn5      [        R                  R                  U
R                   Vs/ s H  nUR                  PM     sn5      5       H  nSX'   M	     [        U	R                  5       5      nUR	                  XU5      n[        U5      S:X  a  XS      n[        U5      S:  a  [        R                  " S5      eU(       d  [        R                  " SU< S35      eX&4$ s  snf s  snf )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   r?   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   rv   rw   r8  find_left_clause_to_join_fromr  r  ra  rb  rV  r   rk  r  keysr0   ro  )r:   r  r:  r   r   rw   r  r8  indexes	potentialr  r  from_clauseall_clausess                 r;   r  .SelectState._join_determine_implicit_left_side9  s    >>**!%((<<XG 7|q )0&#;II(--:EF+w**+F -- (1'@'@'@G  --'@	
  *,	&
  y~~/0K<<HG 7|q "1:.w<!)).  ))
 27	9  ++K Gs   FFc                 2   S n[         R                  R                  n[        U R                  R                  5       5      nU(       a  UR                  U R                  U5      nO/ n[        U5      S:  a  [        R                  " S5      eU(       a  US   nU$ )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   rv   rw   r  r  _iterate_from_elements#find_left_clause_that_matches_givenr8  r  r0   ro  )r:   r:  r  rw   r8  r  s         r;   r  *SelectState._join_place_explicit_left_side  s    !%>>**DNNAACDBB!!4G Gw<!))  %,QZ"
 &%r>   )r:  r8  r9  r  r7   r-  )r@   rA   rB   rC   	__slots__r   r>  rC  r  rI  rM  rP  rW  rg  rD  rU  r{  r  r  r  rB  r1   r   r  r  rF   r?   r>   r;   r7  r7    s!   I")9 "O  
 
 

 

 & & 
 
 & &P
( ! !H GKBH0"   F F'R 
./C, 0C,J 
./& 0&r>   r7  c                       \ rS rSrS rSrg)_SelectFromElementsi  c              #     #    [        5       nU R                   H2  nUR                   H  nX1;   a  M
  UR                  U5        Uv   M!     M4     U R                   H2  nUR                   H  nX1;   a  M
  UR                  U5        Uv   M!     M4     U R
                   H  nX!;   a  M
  UR                  U5        Uv   M!     g 7fr7   )r  rC  r   r  rk  r@  )r:   rq  r  frs       r;   r  *_SelectFromElements._iterate_from_elements  s      u((G++:	 , ) ++G++:	 , , ~~GHHWM	 &s   B?Cr?   N)r@   rA   rB   rC   r  rF   r?   r>   r;   r  r    s    r>   r  c                       \ rS rSrSrS\R                  4S\R                  4S\R                  4S\R                  4/r	\
R                  rS r\S 5       rS	rg
)_MemoizedSelectEntitiesi  memoized_select_entitiesrC  rB  _legacy_setup_joins_with_optionsc                    U R                   R                  U R                   5      nU R                  R                  5        VVs0 s H  u  p4X4_M	     snnUl        U R                  R	                  SU 5      Ul        U$ s  snnf )N_is_clone_of)r   r  r	  r  getr  )r:   r   r  kvs        r;   r   _MemoizedSelectEntities._clone  se    NN""4>>2'+}}':':'<='<tqad'<=
**>4@ >s   A=c                 l   UR                   (       d"  UR                  (       d  UR                  (       a  [        5       nUR                  Ul        UR                   Ul         UR                  Ul        UR                  Ul        U=R
                  U4-  sl        S=Ul        =Ul         =Ul        Ul        g g r  )rB  r  r  r  rC  rA  )rG  select_stmtr:   s      r;   _generate_for_statement/_MemoizedSelectEntities._generate_for_statement  s     $$..((*,D + 8 8D + 8 8D'2'F'FD$!,!:!:D11dW<1
 -/	/K$ /(/ /) )r>   )r  rC  rB  r  N)r@   rA   rB   rC   r   r.   rf  dp_setup_join_tupledp_executable_optionsr  r1   
EMPTY_DICT_annotationsr   r  r  rF   r?   r>   r;   r  r    ss     0N 
*@@A	*>>?	 1 E EF	+AAB	 ??L / /r>   r  c                     ^  \ rS rSrSrSrSrSrSrSr	Sr
SrSrSrSrSrSr\R$                  rS\R*                  4S	\R,                  4S
\R*                  4S\R.                  4S\R.                  4S\R.                  4S\R.                  4S\R0                  4S\R0                  4S\R.                  4S\R.                  4S\R2                  4S\R2                  4S\R2                  4S\R4                  4S\R2                  4S\R6                  4S\R.                  4S\R8                  4/\R<                  -   \R@                  -   \!RD                  -   \#RH                  -   \%RL                  -   \'RP                  -   r)\)S\RT                  4/-   r+\,S 5       r-\,\.R^                  " SS5              SYS j5       5       r0\,S  5       r1\1r2\,S! 5       r3\,S" 5       r4S# r5S$ r6S% r7S& r8S' r9\:S( 5       r;S) r<\=SZS* j5       r>S[S+ jr?\= SZS, j5       r@S[S- jrAS. rB\:\.R^                  " S/S05      S1 5       5       rC\:S2 5       rD\:S3 5       rES4 rF\G4U 4S5 jjrHU 4S6 jrI\=S7 5       rJS8 rK\.R^                  " S9S:5      S; 5       rL\.R                  " S<5      S\S= j5       rN\=S> 5       rO\:S? 5       rP\PrQ\=S@ 5       rR\=SA 5       rS\=SB 5       rT\=SC 5       rU\=SD 5       rV\=SE 5       rW\XR                  SF 5       rZ\XR                  SG 5       r[SH r\S]SI jr]SJ r^SK r_S]SL jr`SM raSN rbSO rcSP rdSQ reSR rf\:\.R                  " SSSTSSU9SV 5       5       rh\hR                  SW 5       rhSXrjU =rk$ )^rI   i  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   r?   FNTrC  rA  r@  rk  _having_criteriar  rz  rB  r  rv  rw  r  r  r  r  rk  	_distinct_distinct_onr  _compile_optionsc                 x    U(       d  U(       a  [         R                  " U/UQ70 UD6$ [         R                  " U6 $ r7   )rI   rJ   _create_select)rG  targetentitiesr  r   s        r;   r   %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	           	         U R                  U 5      n
Xjl        USLaR  USL a  U
R                  R                  U
5        O1U
R                  R                  " U
/[        R
                  " U5      Q76   Ub1  U
R                  R                  " U
/[        R
                  " U5      Q76    [        U5      nW(       a:  U Vs/ s H&  n[        R                  " [        R                  XS9PM(     snU
l        O/ U
l        Ub  U
R"                  R                  X5        Ub  U
R$                  R                  X5        U(       a  U
R'                  U5        U(       a  U
R)                  U5        [*        R,                  " U
40 U	D6  U
$ ! [         a3  n[        R                  " [        R                  " SSS9US9   SnAGNSnAff = fs  snf )	aM  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  distinctrT  r1   r  r  r  	TypeErrorr  r0   r   r   r   r   r  rC  r+  r/  r   r   r^  rC  )rG  r  r   from_objr  r/  r  r   r   rN   r:   cols_presentr  r  s                 r;   rJ   Select.create_legacy_select6  s   | {{3(5 4,,T2,,TKDLL4JK++DJ4<<3IJ	=L 
 !	! !A   ++Q !	!D !#D"JJ%%d8KK&&t4  *  *!!$1&1E  		KK!!7  	  		!s   $E< :-F<<
F9(F44F9c           	          U R                  U 5      nU Vs/ s H&  n[        R                  " [        R                  X2S9PM(     snUl        [        R                  U5        U$ s  snf )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  rC  r^  rC  )rG  r  r:   ents       r;   _create_future_selectSelect._create_future_selectG  si    N {{3
  	
   ''  	
 	!!$'
s   -A"c                 n    [         R                  [         5      nUR                  R                  U5        U$ )zCreate a :class:`.Select` using raw ``__new__`` with no coercions.

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

)rI   r  r	  r`  )rG  r   r  s      r;   _create_raw_selectSelect._create_raw_select|  s)     ~~f%R r>   c                 P   U(       ax  [        US   [        5      (       dg  [        US   S5      (       aL  [        US   [        R                  [
        4-   5      (       d"  [        US   SS9c  [        US   S5      (       a  U(       a  U R                  " U0 UD6$ U R                  " U6 $ )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__)	rh  r  hasattrr1   string_typesr&   r2   rJ   r  )rG  rM   r   s      r;   _createSelect._create  s    R 47D))DGZ00&Q!2!2m5E!E   Q%8@#DG-ABB ++T8R88,,d33r>   c                     [        5       er7   rV   r9   s    r;   rC  Select.__init__  rj   r>   c                 h    U R                   S   n[        UR                  5      nUS   R                  $ r  )rC  r  r5  r  )r:   r  colss      r;   r  Select._scalar_type  s0      #D))*Aw||r>   c                      U R                   " U6 $ )z6A synonym for the :meth:`_future.Select.where` method.r+  )r:   criterias     r;   filterSelect.filter  s     zz8$$r>   c                     U R                   (       a,  [        R                  U 5      R                  nU" U 5      nUb  U$ U R                  (       a  U R                  S   $ U R
                  S   $ r  )rB  r7  get_plugin_classr  r@  rC  )r:   meth_last_joined_entitys      r;   _filter_by_zeroSelect._filter_by_zero  sf    //**  #'t*".**>>>>!$$  ##r>   c                     U R                  5       nUR                  5        VVs/ s H  u  p4[        X#5      U:H  PM     nnnU R                  " U6 $ s  snnf )zGapply the given filtering criterion as a WHERE clause
to this select.

)r  r  r   r  )r:   rN   from_entityr  r  rV  s         r;   	filter_bySelect.filter_by  s\    
 **, %lln
,
 "+3u<, 	 
 {{G$$	
s   Ac                 P    [         R                  U 5      R                  nU" U 5      $ )aE  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

)r7  r  rM  r:   r  s     r;   column_descriptionsSelect.column_descriptions  s%    R ++D1IIDzr>   c                 P    [         R                  U 5      R                  nU" X5      $ )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

)r7  r  rP  )r:   r  r  s      r;   rP  Select.from_statement  s%    ( ++D1@@D$$r>   c                     [         R                  " [        R                  XS9nUb%  [         R                  " [        R                  U5      nU =R
                  XSX4S.44-  sl        g)a8  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  NrF  )r   r   r   JoinTargetRolerA  rB  )r:   r  r   r   r   s        r;   r   Select.join.  sc    v !!  &
  ''(:(:HEHt%GH
 	
r>   c                 &    U R                  XUSUS9$ )zCreate 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)r:   r  r  r   r   s        r;   outerjoin_fromSelect.outerjoin_fromr  s#     ~~Hd  
 	
r>   c                    [         R                  " [        R                  XS9n[         R                  " [        R                  X S9nUb%  [         R                  " [        R
                  U5      nU =R                  X#XUS.44-  sl        g)aA  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  NrF  )r   r   r   r   r  rA  rB  )r:   r  r  r   r   r   s         r;   r  Select.join_from~  s    b     %
 !!  &
  ''(:(:HEHu4&HI
 	
r>   c                 $    U R                  XSUS9$ )a1  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   )r:   r  r   r   s       r;   r   Select.outerjoin  s    F yyDtyLLr>   c                 B    U R                  U S5      R                  5       $ )ao  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{  r9   s    r;   get_final_froms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                 "    U R                  5       $ )zIReturn the displayed list of :class:`_expression.FromClause`
elements.


)r
  r9   s    r;   r9  Select.froms  s     ##%%r>   c                 J    [         R                  U 5      R                  U 5      $ )aa  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

)r7  r  rW  r9   s    r;   columns_clause_fromsSelect.columns_clause_froms  s%    " ++D1JJ
 	
r>   c                 ,    [        U R                  5      $ )a  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.

)iterrX   r9   s    r;   inner_columnsSelect.inner_columns+  s     D..//r>   c                     XR                   ;   a  gU R                  5        H  nUR                  U5      (       d  M    g   gr  )r   r  r   )r:   r   rv  s      r;   r   Select.is_derived_from8  s=    ))),,.A  ,, / r>   c                 |  >^	 [        [        R                  " [        U R                  6 [        U R
                  6 [        U R                   Vs/ s H  o3S   PM	     sn6 5      5      nU Vs0 s H  oUU" U40 UD6_M     snm	U R                   Vs/ s H  oQ" U40 UD6PM     nn[        S T	R                  5        5       5      R                  U5      R                  U5      n[        U5      [        U5      -   U l        U	4S jnXS'   [        [        U ]6  " SUSS.UD6  U R                  5         g s  snf s  snf s  snf )Nr   c              3   T   #    U  H  n[        U[        5      (       d  M  Uv   M      g 7fr7   )rh  r   r  s     r;   r   )Select._copy_internals.<locals>.<genexpr>]  s     E-aAt1D-s   (	(c                    > [        U [        5      (       a1  U R                  T;   a   TU R                     R                  U 5      nU$ g g r7   rg  rj  s      r;   rn  'Select._copy_internals.<locals>.replacef  rp  r>   rn  )r@  )rq  
omit_attrsr?   )r  ra  rb  r   rC  rk  rB  r@  r  
differencer   rr  rI   rs  rt  )r:   rq  r   r  ru  rv  existing_from_obj	add_fromsrn  rm  r   s            @r;   rs  Select._copy_internalsA  s7    OOt001t334D4E4EF4EDQ4EFG
 1>>1a2&>	 6:^^D^U1^^^DE9++-EEZ&Z)* 	 01E)4DD	
  9 	fd+ 	
N	
68	
 	  "O  G ? Es   D/+D4D9c                 p   > [         R                  " [        [        U ]  / SQS9U R                  5       5      $ )N)r@  rv  rw  )r  )ra  rb  rr  rI   get_childrenr  )r:   rN   r   s     r;   r"  Select.get_childrenw  s9    &$,K -  '')	
 	
r>   c           
          U R                  5         U R                  U Vs/ s H&  n[        R                  " [        R
                  X S9PM(     sn-   U l        gs  snf )aV  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)rt  rC  r   r   r   r  )r:   r  rg   s      r;   r%  Select.add_columns  s_     	  " -- "	1
 " '' "	1
 
 1
s   -Ac           	          [         R                  " U5       Vs/ s H&  n[        R                  " [        R
                  X S9PM(     snU l        g s  snf )Nr  )r1   r  r   r   r   r  rC  )r:   r  r  s      r;   _set_entitiesSelect._set_entities  sL    
 ||H-	
 . '' .	
 
s   -ArG   zThe :meth:`_expression.Select.column` method is deprecated and will be removed in a future release.  Please use :meth:`_expression.Select.add_columns`c                 $    U R                  U5      $ )aP  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.

)r%  rf   s     r;   rg   Select.column  s    ( ''r>   rt   c                     U R                   " [        R                  R                  R                  " U R
                  /U R                  U R                  -   Q7SU066 $ )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   rv   rw   r_  rX   rk  r@  )r:   r,  s     r;   r_  Select.reduce_columns  sY    0 %%^^$$33** &&7+
 	
r>   c                    U R                  5         UR                  SS5      nU(       a  [        SSR                  U5      < 35      eU(       a'  U R                  R
                  " U /U R                  Q76   [        R                  U 5        [        R                  " SSU5       Vs/ s H(  n[        R                  " [        R                  U5      PM*     snU l        gs  snf )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  rT  r  r  r  r   !_expression_collection_was_a_listr   r   r  rC  )r:   r  r   r0  r  s        r;   r-  Select.with_only_columns  s    t 	$$& "'> F		"GHH ++DM43L3LM 	 77= @@5w
 U44a8
 
s   %/Cc                 B    [         R                  " U R                  5      $ )zReturn 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_whereclauserk  r9   s    r;   r   Select.whereclause"  s      !;;  
 	
r>   c                     [        U R                  [        5      (       d   eU H>  n[        R                  " [
        R                  U5      nU =R                  U4-  sl        M@     g)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)rh  rk  r   r   r   r   WhereHavingRole)r:   r   	criterionwhere_criterias       r;   r+  Select.where5  sS     $..6666$I&--e.C.CYON  ^$55  %r>   c                 v    U =R                   [        R                  " [        R                  U5      4-  sl         g)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   r8  r0  s     r;   r/  Select.havingC  s0     	U22F;"
 	
r>   c                 x    U(       a,  SU l         U R                  [        S U 5       5      -   U l        gSU l         g)ay  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   l   #    U  H*  n[         R                  " [        R                  U5      v   M,     g 7fr7   )r   r   r   ByOfRole)r   r  s     r;   r   "Select.distinct.<locals>.<genexpr>]  s'      :=A	  33Tr  N)r  r  r   )r:   r   s     r;   r  Select.distinctN  s>     !DN $ 1 1E :=A: 5 !D "DNr>   c                 V   ^  T =R                   [        U 4S jU 5       5      -  sl         g)aL  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   l   >#    U  H)  n[         R                  " [        R                  UTS 9v   M+     g7f)r  Nr   r   r   r   )r   r   r:   s     r;   r   %Select.select_from.<locals>.<genexpr>  s4       
 $
 $$j $s   14N)r@  r   )r:   r9  s   ` r;   r  Select.select_fromc  s*    H 	%  
 $	 
 
 	
r>   c                     SU l         U(       a  US   S;   a  SU l        gU R                  [        S U 5       5      -   U l        g)a  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      FNr?   c              3   l   #    U  H*  n[         R                  " [        R                  U5      v   M,     g 7fr7   rE  r  s     r;   r   #Select.correlate.<locals>.<genexpr>  s)      6CNa	  !5!5q99;r  N)r  rv  r   r:   fromclausess     r;   r  Select.correlate  sF    j  %;q>]: DO"oo 6CN6 1 DOr>   c                     SU l         U(       a  US   S;   a  SU l        gU R                  =(       d    S[        S U 5       5      -   U l        g)aK  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   rI  r?   c              3   l   #    U  H*  n[         R                  " [        R                  U5      v   M,     g 7fr7   rE  r  s     r;   r   *Select.correlate_except.<locals>.<genexpr>  s*      LCNa	  !5!5q99;r  N)r  rw  r   rL  s     r;   correlate_exceptSelect.correlate_except  sQ    <  %;q>]:%'D"&*&<&<&Be LCNL G &D"r>   c                     [         R                  U R                  5      n[        U R                   Vs/ s H   nUR
                  (       a  M  U" U5      U4PM"     sn5      R                  5       $ s  snf )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

)r7  rg  r  r   rX   r\  r  )r:   convr  s      r;   r   Select.selected_columns  sl    ^ 44T5F5FG 333A(( a!3
 ,.	s   A/A/c                 b    [         R                  U 5      R                  n[        U" U 5      5      $ r7   )r7  r  r  r  r  s     r;   rX   Select._all_selected_columns*  s'    ++D1FFDJr>   c                 V    U R                   [        L a  U R                  [        5      n U $ r7   )r  r6  r  r8  r9   s    r;   r"  "Select._ensure_disambiguated_names/  s'     00''(EFDr>   c                    Uc  U R                   n[        R                  U R                  5      n0 n/ nUR                  nU R                  [
        L nU R                  [        L nSn	U GH  n
SnU
R                  (       d  S=n=nnOU(       a#  S=pU
R                  =(       d    U
R                  nOU(       a  U
R                  =n=nnOU
R                  =pSnUc~  U
R                  nUci  U
R                  U;   nXU
R                  '   S=pU(       a5  U(       a  U
R                  U	5      nU	S-  n	O*U
R                  U	5      nU	S-  n	OU
R                  nOU=n=nnUb  X;   a  [        XL   5      [        U
5      :w  a  U(       a  U
R                  =nnOU
R                  =nnU(       a\  X;   aW  [        XM   5      [        U
5      :X  d   eU(       a  U
R                  U	5      =nnU	S-  n	OU
R                  U	5      =nnU	S-  n	SnOKXU'   OFU(       a:  U(       a  U
R                  U	5      =nnU	S-  n	OU
R                  U	5      =nnU	S-  n	SnOXU'   U" UU" U
5      UU
U45        GM     U$ )a3  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)rX   r7  rg  r  r  r7  r6  _render_label_in_columns_clause_non_anon_label_anon_name_labelr  _expression_label_dedupe_anon_tq_label_idx_dedupe_anon_label_idxrQ  _anon_tq_label)r:   rB  r  key_naming_conventionrb  resultresult_appendrd  label_style_nonededupe_hashr  repeatedeffective_namerequired_label_namefallback_label_name
expr_labels                   r;   rA  #Select._generate_columns_plus_names4  s    <--D + E E!
 ++/MM,,0@@ AH44 +// /''!7;;&'&7&7&M1;M;M#" /0kk:' :&+;<;L;LLN*.'!) "#!4!4J!)#$#5#5#>45a001?CC#  /$%$?$?$L !4 !,q 0676N6N$/7" 3 !,q 0232D2D/ 3==+ =*/)!* E12d1g= + !" 0 01/ 3
 !" 2 23/ 3 -1D1M $((B#CtAw#NN#N  / %&$?$?$L!M 3$7 +q 0 %&$<$<[$I!J 3$7 +q 0'+H9:"56* + !" ; ;K HI/ 3'1,K !" 8 8 EF/ 3'1,K#',-.) ( *!, ( ![ D r>   c                     U R                  S5       VVVVVs/ s H.  u  nnnnnUR                  (       a  M  UR                  UUUSS9PM0     nnnnnnUR                  R	                  U5        gs  snnnnnf )zQGenerate column proxies to place in the exported ``.c``
collection of a subquery.FT)r  rp   name_is_truncatableN)rA  r\  r   r   r   )r:   rK   rj  	proxy_keyrk  r  rh  proxs           r;   r  *Select._generate_fromclause_column_proxies  s    " 33E:
 ;##$$AMM($(	   ; 	 
" 	11$7#
s
   A/A/c                 f    U R                   =(       d    [        U R                  R                  5      $ r7   )r  r  r  rV  r9   s    r;   _needs_parens_for_grouping!Select._needs_parens_for_grouping  s+    ,, 
!!))1
 	
r>   c                 p    [        U[        5      (       a  U R                  5       (       d  U $ [        U 5      $ )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.

)rh  r  rt  r*  rU  s     r;   r?  Select.self_group  s0     w//3355K*400r>   c                 6    [         R                  " U /UQ70 UD6$ )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  r:   r   rN   s      r;   r   Select.union  s     ++DC5CFCCr>   c                 6    [         R                  " U /UQ70 UD6$ )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  ry  s      r;   rX  Select.union_all       //GuGGGr>   c                 6    [         R                  " U /UQ70 UD6$ )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  ry  s      r;   except_Select.except_)  s     ,,TDEDVDDr>   c                 6    [         R                  " U /UQ70 UD6$ )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  ry  s      r;   
except_allSelect.except_all:  s     00HHHHr>   c                 6    [         R                  " U /UQ70 UD6$ )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  ry  s      r;   	intersectSelect.intersectK  r}  r>   c                 6    [         R                  " U /UQ70 UD6$ )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  ry  s      r;   intersect_allSelect.intersect_all\  s     33DK5KFKKr>   r  r  r  c                 r   U R                   (       a  U R                   $ U R                  5        HV  nUR                  (       a%  UR                  U L a  [        R
                  " S5      eUR                  nU(       a
  X l         Us  $   O   U R                   H   nUR                  nU(       d  M  X l         Us  $    g)r  rn  N)rg  r  rz  r  r0   ro  r  rC  )r:   rr  r  r  s       r;   r  Select.bindm  s     :::://1D  T\\T%9--C  		A
 2 ""AAq
	 #r>   c                     Xl         g r7   r  r  s     r;   r  r    r  r>   )r  rg  rv  rw  r  r  r@  rC  )NNNFNTNNr+  r,  )Tr7   )lr@   rA   rB   rC   r]   r   rB  r  rA  r  r  rv  rw  rk  r  r@  r  r7  r>  r  r.   rf  dp_memoized_select_entitiesdp_clauseelement_tupler  r  r  r  dp_plain_objr^  rg  r   r   r   r   r   r   r   r  r   _executable_traverse_internalsr  dp_has_cache_keyr=  r  r   r1   r   rJ   r  r  r  r  rC  r  r  r  r  rE   r  rP  r   r   r  r  r   r
  r9  r  r  r   r   rs  r"  r%  r'  rg   r   r_  r-  r   _whereclauser+  r/  r  r  r  rR  r   r1  r   rX   r"  rA  r  rt  r?  r   rX  r  r  r  r  r  r  r  rF   r  r  s   @r;   rI   rI     sL    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 	__	2 H HT 0 0d +N
 
 74 74r$
%
$% ) )V%. A
 A
F

 @E;
 ;
z#MJ%LN 	__	A
& & 
 
( 
0 
0 %+ 4#l
 
 
.
 
__	1((  
./
 0
> J
 J
X 
 
  L6 6 
 
 " "( (
 (
T : :x # #J ##6 $6p ##  $ 
dL8.

1"D"H"E"I"H"L" 	"K
 6 
[[ r>   rI   c                   x    \ rS rSrSr/ rSrSrSrS r	\
S 5       r\r\S 5       rS r\S	 5       r\S
 5       rSrg)r  i  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                 :    Xl         UR                  5       U l        g r7   )r  r  r  r}  s     r;   rC  ScalarSelect.__init__  s    ((*	r>   c                 .    [         R                  " S5      e)NzcScalar Select expression has no columns; use this object directly within a column-level expression.)r0   ro  r9   s    r;   r  ScalarSelect.columns  s    %%0
 	
r>   c                 D    U R                   R                  U5      U l         g)zeApply a WHERE clause to the SELECT statement referred to
by this :class:`_expression.ScalarSelect`.

N)r  r+  )r:   r  s     r;   r+  ScalarSelect.where  s     ||))$/r>   c                     U $ r7   r?   )r:   rN   s     r;   r?  ScalarSelect.self_group  r?  r>   c                 @    U R                   R                  " U6 U l         g)aK  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  rL  s     r;   r  ScalarSelect.correlate  s    8 ||--{;r>   c                 @    U R                   R                  " U6 U l         g)aL  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  rR  rL  s     r;   rR  ScalarSelect.correlate_except  s    < ||44kBr>   )r  r  N)r@   rA   rB   rC   r]   r   r  _is_implicitly_booleanrD   rC  rE   r  r  r   r+  r?  r  rR  rF   r?   r>   r;   r  r    s      M"M+ 
 
 	A0 0 < <: C Cr>   r  c                   v    \ rS rSrSr/ rSrS rS r\	R                  " SSS9SS
 j5       rS rS rS rS rSrg	)r  i  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                 0   U(       a$  [        US   [        [        45      (       a  US   nO7U(       d  [        S5      4n[        R
                  " U0 UD6R                  5       n[        R                  " U U[        R                  [        R                  SS9  g)a8  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)rh  r  r  r+   rI   r  rn  r-   rC  r   r  r	   BOOLEANTYPE)r:   rM   rN   r  s       r;   rC  Exists.__init__  s{    J JtAw\(BCCQA&s+-//??AA  %%&&$(	
r>   c                     U R                   R                  5       nU" U5      nUR                  [        R                  S9$ )Nr=  )r  _ungroupr?  r   r  )r:   fnr  s      r;   _regroupExists._regroupB  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                 @    Ub  XS'   [         R                  " X /40 UD6$ )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   Exists.selectG  s+    V "$/=!44T6LVLLr>   c                 \   ^ U R                  5       nU R                  U4S j5      Ul        U$ )z~Apply correlation to the subquery noted by this
:class:`_sql.Exists`.

.. seealso::

    :meth:`_sql.ScalarSelect.correlate`

c                 "   > U R                   " T6 $ r7   )r  r  r   s    r;   r  "Exists.correlate.<locals>.<lambda>  s    G--z:r>   r   r  r  r:   r   r  s    ` r;   r  Exists.correlatev  s*     KKMMM:
	 r>   c                 \   ^ U R                  5       nU R                  U4S j5      Ul        U$ )zApply correlation to the subquery noted by this
:class:`_sql.Exists`.

.. seealso::

    :meth:`_sql.ScalarSelect.correlate_except`

c                 "   > U R                   " T6 $ r7   )rR  r  s    r;   r  )Exists.correlate_except.<locals>.<lambda>  s    G44jAr>   r  r  s    ` r;   rR  Exists.correlate_except  s*     KKMMMA
	 r>   c                 \   ^ U R                  5       nU R                  U4S j5      Ul        U$ )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                 "   > U R                   " T6 $ r7   )r  )r  r9  s    r;   r  $Exists.select_from.<locals>.<lambda>  s    '2E2Eu2Mr>   r  )r:   r9  r  s    ` r;   r  Exists.select_from  s&     KKMMM"MN	r>   c                 \   ^ U R                  5       nU R                  U4S j5      Ul        U$ )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                 "   > U R                   " T6 $ r7   r  )r  r  s    r;   r  Exists.where.<locals>.<lambda>  s    '--2Hr>   r  )r:   r  r  s    ` r;   r+  Exists.where  s&     KKMMM"HI	r>   r?   r7   )r@   rA   rB   rC   r]   r   rD   rC  r  r1   r3  r   r  rR  r  r+  rF   r?   r>   r;   r  r    s]     MM2
h<
 


$M%$M: "r>   r  c                      \ rS rSrSrSr\rS\R                  4S\R                  4/\R                  -   \R                  -   rSrSrSrSS jr\R*                  S 5       r\S	 5       rS
 rS r\S 5       r\S 5       rS rS rSr g)TextualSelecti  a  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                     Xl         U Vs/ s H(  n[        R                  " [        R                  U5      PM*     snU l        X0l        g s  snf r7   )r  r   r   r   r  r  
positional)r:   r   r  r  r  s        r;   rC  TextualSelect.__init__  sF     CJ
BIQIU44a8'
 %
s   /A	c                 V    [        S U R                   5       5      R                  5       $ )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 :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   <   #    U  H  oR                   U4v   M     g 7fr7   r  rY  s     r;   r   1TextualSelect.selected_columns.<locals>.<genexpr>  s       
 01UUAJ 0r]  )r   r  r  r9   s    r;   r   TextualSelect.selected_columns  s+    ,    
 $ 0 0 
 

,.	r>   c                     U R                   $ r7   )r  r9   s    r;   rX   #TextualSelect._all_selected_columns  s    r>   c                     U $ r7   r?   rq  s     r;   r  TextualSelect._set_label_style  r?  r>   c                     U $ r7   r?   r9   s    r;   r"  )TextualSelect._ensure_disambiguated_names  r?  r>   c                 .    U R                   R                  $ r7   )r  rg  r9   s    r;   rg  TextualSelect._bind  s    ||!!!r>   c                 F    U R                   R                  " U0 UD6U l         g r7   )r  
bindparams)r:   bindsbind_as_valuess      r;   r  TextualSelect.bindparams  s    ||..HHr>   c                 d   ^ TR                   R                  U4S jU R                   5       5        g )Nc              3   D   >#    U  H  oR                  T5      v   M     g 7fr7   r   )r   r  r   s     r;   r   DTextualSelect._generate_fromclause_column_proxies.<locals>.<genexpr>  s      4
/?!MM*%%/?r   )r   r   r  r   s    `r;   r  1TextualSelect._generate_fromclause_column_proxies  s*    33 4
/3/?/?4
 	
r>   c                 4    U R                   S   R                  $ r  )r  r  r9   s    r;   r  TextualSelect._scalar_type  s    "'''r>   )r  r  r  Nr   )!r@   rA   rB   rC   r]   r   r6  r  r.   r  rf  r   r  r^  rg  r  _is_textualis_textr(  rC  r   r1  r   rE   rX   r  r"  rg  r   r  r  r  rF   r?   r>   r;   r  r    s    6 &N#L )::;-CCD	
 #
H
H		I
 
-
-	.  KGI% ## $2     " " I I

(r>   r  c                       \ rS rSrS rSrg)AnnotatedFromClausei&  c                 J    UR                     [        R                  " XU5        g r7   )r  r   rC  )r:   r  r  s      r;   rC  AnnotatedFromClause.__init__'  s     			4&1r>   r?   Nr  r?   r>   r;   r  r  &  s    2r>   r  )qr]   r  ra  r  r   r  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!   r  r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r0   r1   
inspectionr2   r4   r   rK   r  rP   rc   objectr   r   r   AnonymizedFromClauseRoler   r  r6  r7  r8  r  DMLTableRoler   r  r  r   r  rm   r   ra  rE  rL  r^  ri  rT  r  r  r  rk  DMLSelectRoler  InElementRoler  r*  rQ  r^  
plugin_forr  r  r   MemoizedSlotsr7  r  HasCacheKeyHasCopyInternalsTraversibler  rI   r  r  r  
TextAsFromr  r?   r>   r;   <module>r     s&            ! 0  $ & '     # " "   (   !   ! . &  # ' #   " $  $ ' % '    $ $ 	I

H

H<$%'' <$~K
 K
\5
& 5
p0
& 0
fQv Qh%// %D ;; . "&$" > !%#! 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 @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h(J h(V 
 42) 2r>   