PK APOCALYPSE V1

APOCALYPSE V1

Current Path : /opt/hc_python/lib/python3.12/site-packages/sqlalchemy/sql/__pycache__/
Upload File :
Current File : //opt/hc_python/lib/python3.12/site-packages/sqlalchemy/sql/__pycache__/selectable.cpython-312.pyc

�

���g����
�dZddlmZddlZddlmZddlZddlmZddlm	Z
ddlm	Z	ddlmZddlmZdd	lm
Z
dd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#dd lm$Z$dd!l%m&Z&dd"l%m'Z'dd#l%m(Z(dd$l%m)Z)dd%l%m*Z*dd&l%m+Z+dd'l%m,Z,dd(l%m-Z-dd)l%m.Z.dd*l/m0Z0dd+l/m1Z1dd,l2m3Z3dd-l2m4Z4dd.l2m5Z5dd/l2m6Z6dd0l2m7Z7dd1l2m8Z8dd2l2m9Z9dd3l2m:Z:dd4l2m;Z;dd5l2m<Z<dd6l2m=Z=dd7l2m>Z>dd8l2m?Z?dd9l2m@Z@dd:l2mAZAdd;l2mBZBdd<l2mCZCdd=l2mDZDdd>l2mEZEdd?l2mFZFdd@l2mGZGddAlmHZHddBlImJZJddClImKZKddDlImLZLddElImMZMddFlImNZNddGlImOZOddHlImPZPddIlImQZQddJlImRZRddKlImSZSddLlImTZTddMlImUZUddNl mVZVddOlWmXZXddPl$mYZYddQl$mZZZddRl$m[Z[dSdTlm\Z\dSdUlm]Z]dSdVl]m^Z^dSdWl_m`Z`dSdXl_maZadSdYl_mbZbeLj�Zcer�ddZl%mdZddd[l%meZedd\l%mfZfdd]l%mgZgdd^l%mhZhdd_l%miZidd`l%mjZjddal%mkZkddbl%mlZlddcl%mmZmdddl%mnZnddel%moZoddfl%mpZpddgl%mqZqddhl%mrZrddil%msZsddjl%mtZtddkl%muZuddll%mvZwddml%mxZxddnl2myZyddol2mzZzddpl2m{Z{ddqlm|Z|ddrl}m~Z~ddslm�Z�ddtlm�Z�ddulIm�Z�ddvlIm�Z�ddwlIm�Z�ddxlIm�Z�ddylIm�Z�ddzl�m�Z�dd{l�m�Z�dd|l�m�Z�dd}lWm�Z�dd~l#m�Z�ddl$m�Z�ed�ePe	d�fZ�eed�gee�fZ�Gd��d�ea�Z�ed�e�fZ�ed�e�fZ�eed�ed�fZ�ee�ee�ed�e
e�e	ffZ�eed�Z�Gd��d�eKe��Z�Gd��d�e!�j4eQ�Z�Gd��d�eCe��Z�Gd��d�e�ee)�Z�Gd��d�e��Z�Gd��d��Z�Gd��d��Z�Gd��d��Z�Gd��d�e!�jDe��Z�Gd��d�e��Z�Gd��d�e�Z�e�e��\Z�Z�Z�Z�e�Z�Gd��d�e!�jXe��Z�Gd��d��Z�Gd��d�e��Z�Gd��d�e�e��Z�Gd��d�e��Z�Gd��d�e!�jXe��Z�Gd��d�e�e��Z�Gd��d�e�e��Z�Gd��d�e��Z�Gd��d�e!�jXe!�jleDe�e�e��Z�Gd��d�e�Z�Gd��d�e�Z�Gd��d�e��Z�Gd��d�e!�jve��Z�Gd��d�e��Z�Gd��d�eRe��Z�Gd��d�e�e��Z�Gd��d�e!�jXeGe��Z�ed�de�e
e�e	ffZ�Gd„d�eM�Z�GdÄd�e!�j�eDe��Z�Gdńd�e!�j�eRePe	�Z�GdDŽd�e!�j�e!�j�e!�j�e!�j�e�e1e��	Z�ed�eʬʫZ�Gd˄d�eRe�ee��Z�Gd̈́d�e�eD�Z�eA�j�d�dЫGdфd�eA��Z�Gdӄd�e�Z�GdՄd�eEe�e�e)�Z�e�D]Z�e�e�eҐj�eҫ�eA�j�d�d׫Gd؄d�e]�j�eA��Z�Gdڄd۫Z�Gd܄d�e�j�e"�j�e$�j��Z�Gdބd�e�e�e�eEe�e�e�e)�	Z�Gd�d�e!�j�eDeRePe(�Z�Gd�d�eUe��Z�Gd�d�e�e�eD�Z�e�Z�	Gd�d�e0�Z�y)�ztThe :class:`_expression.FromClause` class of SQL expression elements,
representing
SQL tables and derived rowsets.

�)�annotationsN)�Enum)�AbstractSet)�Any)�Callable)�cast)�Dict)�Generic)�Iterable)�Iterator)�List)�
NamedTuple)�NoReturn)�Optional)�overload)�Sequence)�Set)�Tuple)�Type)�
TYPE_CHECKING)�TypeVar)�Union�)�	cache_key)�	coercions)�	operators)�roles)�
traversals)�type_api)�visitors)�_ColumnsClauseArgument)�_no_kw)�_T)�_TP)�is_column_element)�is_select_statement)�is_subquery)�is_table)�is_text_clause)�	Annotated)�SupportsCloneAnnotations)�_clone)�_cloned_difference)�_cloned_intersection)�_entity_namespace_key)�_EntityNamespace)�_expand_cloned��
_from_objects)�_generative��_never_select_column)�_NoArg)�_select_iterables)�CacheableOptions)�ColumnCollection)�	ColumnSet)�CompileState)�DedupeColumnCollection)�
Executable)�
Generative)�HasCompileState)�HasMemoized)�	Immutable)�_document_text_coercion)�_anonymous_label)�
BindParameter)�BooleanClauseList)�
ClauseElement)�
ClauseList)�ColumnClause)�
ColumnElement)�DQLDMLClauseElement)�GroupedElement)�literal_column)�TableValuedColumn)�UnaryExpression)�OperatorType)�NULLTYPE)�_TraverseInternalsType)�InternalTraversal)�prefix_anon_map�)�exc)�util)�!HasMemoized_ro_memoized_attribute)�Literal)�Protocol)�Self)�_ColumnExpressionArgument)�#_ColumnExpressionOrStrLabelArgument)�_FromClauseArgument)�_JoinTargetArgument)�_LimitOffsetType)�
_MAYBE_ENTITY)�_NOT_ENTITY)�_OnClauseArgument)�#_SelectStatementForCompoundArgument)�_T0)�_T1)�_T2)�_T3)�_T4)�_T5)�_T6)�_T7)�_TextCoercedExpressionArgument)�_TypedColumnClauseArgument)�_TypeEngineArgument)�_AmbiguousTableNameMap)�ExecutableOption)�ReadOnlyColumnCollection)�_CacheKeyTraversalType)�SQLCompiler)�Delete)�Update)�BinaryExpression)�KeyedColumnElement)�Label)�NamedColumn)�
TextClause)�Function)�
ForeignKey)�ForeignKeyConstraint)�TableValueType)�
TypeEngine)�_CloneCallableType�
FromClauser{)�ColumnElement[Any]r{c�X�eZdZejdd��Zejdd��Zy)�_JoinTargetProtocolc��y�N���selfs �J/opt/hc_python/lib64/python3.12/site-packages/sqlalchemy/sql/selectable.pyr3z!_JoinTargetProtocol._from_objects�s��14�c��yr�r�r�s r��entity_namespacez$_JoinTargetProtocol.entity_namespace�s��47r�N��return�List[FromClause]�r�r0)�__name__�
__module__�__qualname__rW�ro_non_memoized_propertyr3r�r�r�r�r�r��s*��	�"�"�4�#�4�	�"�"�7�#�7r�r��ColumnElement[bool])�_ColumnExpressionArgument[Any]r^r�c�"�eZdZdZedd��Zy)�_OffsetLimitParamTc��|jSr�)�effective_valuer�s r��_limit_offset_valuez%_OffsetLimitParam._limit_offset_value�s���#�#�#r�N�r��
Optional[int])r�r�r��
inherit_cache�propertyr�r�r�r�r�r��s���M�
�$��$r�r�c��eZdZdZdZdZdZdZdZe	dd��Z
ejdd��Z
d
d�Z										dd�Zdd�Ze	dd	��Zy
)�ReturnsRowsa�The base-most class for Core constructs that have some concept of
    columns that can represent rows.

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

    .. versionadded:: 1.4

    TFc��|Sr�r�r�s r��
selectablezReturnsRows.selectable�s���r�c��t��)aEA 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`.

        ��NotImplementedErrorr�s r��_all_selected_columnsz!ReturnsRows._all_selected_columns�s
��"�#�#r�c��t��)z�Return ``True`` if this :class:`.ReturnsRows` is
        'derived' from the given :class:`.FromClause`.

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

        r��r��
fromclauses  r��is_derived_fromzReturnsRows.is_derived_from��
��"�#�#r�c��t��)z=Populate columns into an :class:`.AliasedReturnsRows` object.r��r�r��columns�primary_key�foreign_keyss     r��#_generate_fromclause_column_proxiesz/ReturnsRows._generate_fromclause_column_proxies�s
��"�#�#r�c��t��)z>reset internal collections for an incoming column being added.r��r��columns  r��_refresh_for_new_columnz#ReturnsRows._refresh_for_new_column�s��!�#�#r�c��t��)aA :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`
        r�r�s r��exported_columnszReturnsRows.exported_columnss
��0"�#�#r�N�r�r��r��_SelectIterable�r��Optional[FromClause]r��bool�
r�r�r��.ColumnCollection[str, KeyedColumnElement[Any]]r�r;r��Set[KeyedColumnElement[Any]]r��None�r�r�r�r�)r�z"ReadOnlyColumnCollection[Any, Any])r�r�r��__doc__�_is_returns_rows�_is_from_clause�_is_select_base�_is_select_statement�_is_lateralr�r�rWr�r�r�r�r�r�r�r�r�r�r��s���
����O��O� ���K�
����
�"�"�	$�#�	$�$�	$��	$�@�	$��		$�
3�	$�
�
	$�$��$��$r�r�c��eZdZdZy)�ExecutableReturnsRowsz0base for executable statements that return rows.N�r�r�r�r�r�r�r�r�r�s��:r�r�c��eZdZdZy)�TypedReturnsRowsz8base for a typed executable statements that return rows.Nr�r�r�r�r�r�!s��Br�r�c��eZdZdZdZdZd
d�Zddd�Zejdd�	�ejd
�dd���Z	d					dd�Zy)�
Selectablez!Mark a class as being selectable.r�Tc��t��r�r�r�s  r�r�z"Selectable._refresh_for_new_column,���!�#�#r�Nc�0�tj||��S)�;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.

        .. seealso::

            :ref:`tutorial_lateral_correlation` -  overview of usage.

        ��name)�Lateral�
_construct�r�r�s  r��lateralzSelectable.lateral/s���!�!�$�T�!�2�2r��1.4z�The :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�tjjj|�j	|�S)z�Replace all occurrences of :class:`_expression.FromClause`
        'old' with the given :class:`_expression.Alias`
        object, returning a copy of this :class:`_expression.FromClause`.

        )rW�	preloaded�sql_util�
ClauseAdapter�traverse)r��old�aliass   r��replace_selectablezSelectable.replace_selectable<s*���~�~�&�&�4�4�U�;�D�D�T�J�Jr�c�:�|jj||�S)a�Given a :class:`_expression.ColumnElement`, return the exported
        :class:`_expression.ColumnElement` object from the
        :attr:`_expression.Selectable.exported_columns`
        collection of this :class:`_expression.Selectable`
        which corresponds to that
        original :class:`_expression.ColumnElement` via a common ancestor
        column.

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

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

        .. seealso::

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

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

        )r��corresponding_column)r�r��require_embeddeds   r�r�zSelectable.corresponding_columnKs$��F�$�$�9�9��$�
�	
r�r�r��r��
Optional[str]r��LateralFromClause)r�r�r��Aliasr�r[�F)r�zKeyedColumnElement[Any]r�r�r��!Optional[KeyedColumnElement[Any]])
r�r�r�r��__visit_name__�
is_selectabler�r�rW�
deprecated�preload_moduler�r�r�r�r�r�r�%s��+�!�N��M�$�3��T�_�_�
�M���T���.�/�K�0�
�K�IN�%
�-�%
�AE�%
�	*�%
r�r�c��eZdZUdZded<dejfgZded<ee	ddd�d	d
�					d
d���Z
y)�HasPrefixesr��+Tuple[Tuple[DQLDMLClauseElement, str], ...]�	_prefixesrR� _has_prefixes_traverse_internals�prefixesz+:meth:`_expression.HasPrefixes.prefix_with`z.:paramref:`.HasPrefixes.prefix_with.*prefixes`�*��dialectc
��|jt|D�cgc](}tjtj
|�|f��*c}�z|_|Scc}w)aqAdd 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 \*prefixes: textual or :class:`_expression.ClauseElement`
         construct which
         will be rendered following the INSERT, UPDATE, or DELETE
         keyword.
        :param dialect: optional string dialect name which will
         limit rendering of this prefix to only that dialect.

        )r��tupler�expectr�StatementOptionRole)r�r�r��ps    r��prefix_withzHasPrefixes.prefix_withzs]��F���%�"�
�!�A��!�!�%�";�";�Q�?��I�!�
�+
�
������
��-A
N)r��#_TextCoercedExpressionArgument[Any]r��strr�r[)r�r�r�r��__annotations__rS�dp_prefix_sequencer�r4rCrr�r�r�r�r�ssz��=?�I�:�?�
�'�:�:�;�@�$�&<�����5�8���#�6�#��#�
�	#���#r�r�c��eZdZUdZded<dejfgZded<ee	ddd�d	d
�					d
d���Z
y)�HasSuffixesr�r��	_suffixesrR� _has_suffixes_traverse_internals�suffixesz+:meth:`_expression.HasSuffixes.suffix_with`z.:paramref:`.HasSuffixes.suffix_with.*suffixes`r�r�c
��|jt|D�cgc](}tjtj
|�|f��*c}�z|_|Scc}w)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 \*suffixes: textual or :class:`_expression.ClauseElement`
         construct which
         will be rendered following the target clause.
        :param dialect: Optional string dialect name which will
         limit rendering of this suffix to only that dialect.

        )rr�rrrr)r�r�r
rs    r��suffix_withzHasSuffixes.suffix_with�s]��H���%�"�
�!�A��!�!�%�";�";�Q�?��I�!�
�+
�
������
rN)r
rr�rr�r[)r�r�r�rrrSrrr4rCrr�r�r�r
r
�sz��=?�I�:�?�
�'�:�:�;�@�$�&<�����5�8���$�6�$��$�
�	$���$r�r
c���eZdZUej�Zded<dZded<dejfdejfgZded<edd
d��Z
e	d							dd	��Z								dd
�Zy)�HasHintsz/util.immutabledict[Tuple[FromClause, str], str]�_hintsr�zTuple[Tuple[str, str], ...]�_statement_hintsrR�_has_hints_traverse_internalsc�(�|jd||�S)aAdd a statement hint to this :class:`_expression.Select` or
        other selectable object.

        .. tip::

            :meth:`_expression.Select.with_statement_hint` generally adds hints
            **at the trailing end** of a SELECT statement.  To place
            dialect-specific hints such as optimizer hints at the **front** of
            the SELECT statement after the SELECT keyword, use the
            :meth:`_expression.Select.prefix_with` method for an open-ended
            space, or for table-specific hints the
            :meth:`_expression.Select.with_hint` may be used, which places
            hints in a dialect-specific location.

        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.

        .. 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 or Oracle Database optimizer hints

        N��
_with_hint)r��text�dialect_names   r��with_statement_hintzHasHints.with_statement_hint�s��B���t�T�<�8�8r�c�(�|j|||�S)a?Add an indexing or other executional context hint for the given
        selectable to this :class:`_expression.Select` or other selectable
        object.

        .. tip::

            The :meth:`_expression.Select.with_hint` method adds hints that are
            **specific to a single table** to a statement, in a location that
            is **dialect-specific**.  To add generic optimizer hints to the
            **beginning** of a statement ahead of the SELECT keyword such as
            for MySQL or Oracle Database, use the
            :meth:`_expression.Select.prefix_with` method.  To add optimizer
            hints to the **end** of a statement such as for PostgreSQL, use the
            :meth:`_expression.Select.with_statement_hint` method.

        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 Database, the
        following::

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

        Would render SQL as:

        .. sourcecode:: sql

            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
        Database and MSSql simultaneously::

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

        .. seealso::

            :meth:`_expression.Select.with_statement_hint`

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

        r�r�r�rrs    r��	with_hintzHasHints.with_hints��t���z�4��>�>r�c���|�|xj||ffz
c_|S|jjtjt
j|�|f|i�|_|Sr�)rr�unionrrr�FromClauseRolers    r�rzHasHints._with_hintDss�����!�!�|�T�&:�%<�<�!����+�+�+�+�"�(�(��)=�)=�z�J�$���	��D�K��r�N)r�)rrrrr�r[)r�r^rrrrr�r[)r�zOptional[_FromClauseArgument]rrrrr�r[)r�r�r�rW�
immutabledictrrrrS�dp_statement_hint_list�dp_table_hint_listrr4rrrr�r�r�rr�s���������;��57��1�6�
�.�E�E�F�	�$�7�7�8�=�!�#9��
� 9�� 9�D�
 �	9?�'�9?��9?��	9?�

�9?��9?�v�1�����	�

�r�rc���eZdZUdZdZdZejd%d��Zde	d<de	d<d	Z
d
e	d<	dZdZdZ
dZd&d
�Z			d'									d(d�Z		d)							d*d�Z	d)					d+d�Z		d,							d-d�Zd.d�Zd/d�Zejd0d��Z										d1d�Zej		d2d��Zej		d2d��Zej4d2d��Zd3d�Zejd4d��Zej4d5d��Zej4d6d��Zd3d�Z ejd7d��Z!e"d8d��Z#								d9d �Z$d:d!�Z%d	dd"�					d;d#�Z&e'r
	d<			d=d$�Z(y	y	)>r�aERepresent 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`.


    r�Fc��y�Nr�r�r�s r��_hide_fromszFromClause._hide_fromsps��r�r��_is_clone_ofzColumnCollection[Any, Any]�_columnsNr��schemaTc��t|�S)a#Return a SELECT of this :class:`_expression.FromClause`.


        e.g.::

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

        .. seealso::

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

        ��Selectr�s r��selectzFromClause.select�s���d�|�r�c� �t|||||�S)aReturn 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:

        .. sourcecode:: sql

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

        .. seealso::

            :func:`_expression.join` - standalone function

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

        ��Join)r��right�onclause�isouter�fulls     r��joinzFromClause.join�s��f�D�%��7�D�9�9r�c� �t|||d|�S)a�Return a :class:`_expression.Join` from this
        :class:`_expression.FromClause`
        to another :class:`FromClause`, with the "isouter" flag set to
        True.

        E.g.::

            from sqlalchemy import outerjoin

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

        The above is equivalent to::

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

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

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

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

        .. seealso::

            :meth:`_expression.FromClause.join`

            :class:`_expression.Join`

        Tr0)r�r2r3r5s    r��	outerjoinzFromClause.outerjoin�s��^�D�%��4��6�6r�c�0�tj||��S)atReturn 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`

        r�)r�r��r�r��flats   r�r�zFromClause.alias�s��*����4��0�0r�c�4�tj||||��S)aWReturn 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.

        .. seealso::

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

        )�samplingr��seed)�TableSampler�)r�r=r�r>s    r��tablesamplezFromClause.tablesamples%��"�%�%��8�$�T�&�
�	
r�c��||jvS)z�Return ``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_setr�s  r�r�zFromClause.is_derived_from)s���T�-�-�-�-r�c�^�t|jj|j��S)z�Return ``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�rB�intersection�r��others  r��_is_lexical_equivalentz!FromClause._is_lexical_equivalent5s&���D�$�$�1�1�%�2C�2C�D�E�Er�c�J�t|d|jjdz�S)z|A brief description of this :class:`_expression.FromClause`.

        Used primarily for error message formatting.

        r�z object)�getattr�	__class__r�r�s r��descriptionzFromClause.description?s"���t�V�T�^�^�%<�%<�y�%H�I�Ir�c�V����|j���fd�|jD��y)Nc3�F�K�|]}|j��������y�w��r�r�N��_make_proxy)�.0�colr�r�r�s  ���r��	<genexpr>zAFromClause._generate_fromclause_column_proxies.<locals>.<genexpr>Os2�����(
���
�O�O���,�
�
����!)�_populate_separate_keys�cr�s ` ``r�r�z.FromClause._generate_fromclause_column_proxiesHs&���	�'�'�(
��v�v�	(
�	
r�c��|jS)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`


        �rWr�s r�r�zFromClause.exported_columnsVs
��,�v�v�
r�c��|jS)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.

        rYr�s r�r�zFromClause.columnsns
�� �v�v�
r�c�r�d|jvr|j�|jj�S)zk
        A synonym for :attr:`.FromClause.columns`

        :return: a :class:`.ColumnCollection`

        r))�__dict__�_setup_collectionsr)�as_readonlyr�s r�rWzFromClause.c�s/���T�]�]�*��#�#�%��}�}�(�(�*�*r�c���d|jvsJ�d|jvsJ�d|jvsJ�t�}t�}t�}|j	|||��||_||_||_y)Nr)r�r�)r�r�r�)r\r:r;�set�_populate_column_collectionr)r�r�)r�r)r�r�s    r�r]zFromClause._setup_collections�s�������.�.�.��D�M�M�1�1�1��T�]�]�2�2�2�/?�/A���k��58�U���(�(��#�%�	)�	
�!��
�&���(��r�c��|jS)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.

        rYr�s r�r�zFromClause.entity_namespace�s
���v�v�
r�c�:�|j�|jS)apReturn 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�r�s r�r�zFromClause.primary_key�s��	
���!����r�c�:�|j�|jS)aVReturn 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�r�s r�r�zFromClause.foreign_keys�s��	
���!�� � � r�c�J�dD]}|jj|d�� y)aReset 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�rWr�r�N)r\�pop)r��keys  r��_reset_column_collectionz#FromClause._reset_column_collection�s$��O�C��M�M���c�4�(�Or�c�(�d�|jD�S)Nc3�8K�|]}t|�r�|���y�wr�r5�rRrWs  r�rTz.FromClause._select_iterable.<locals>.<genexpr>�s����A�6�a�)=�a�)@��6�s��rYr�s r��_select_iterablezFromClause._select_iterable�s��A�4�6�6�A�Ar�c��d|jvS)Nr))r\r�s r��_cols_populatedzFromClause._cols_populated�s���T�]�]�*�*r�c��y)z�Called on subclasses to establish the .c collection.

        Each implementation has a different way of establishing
        this collection.

        Nr��r�r�r�r�s    r�raz&FromClause._populate_column_collection�s�r�c�$�|j�y)aNGiven 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)rhr�s  r�r�z"FromClause._refresh_for_new_column�s��2	
�%�%�'r��r�r;c�&�|j|��S�Nr�)r�r:s   r��_anonymous_fromclausez FromClause._anonymous_fromclauses���z�z�t�z�$�$r�c��yr�r��r��againsts  r��
self_groupzFromClause.self_groups��(+r��r��Iterable[FromClause]�r��Select[Any]�NFF)
r2r^r3�)Optional[_ColumnExpressionArgument[bool]]r4r�r5r�r�r1�NF)r2r^r3rr5r�r�r1)r�r�r;r�r��NamedFromClause�NN)r=�Union[float, Function[Any]]r�r�r>�*Optional[roles.ExpressionElementRole[Any]]r�r?r�)rFr�r�r��r�rr��r�z6ReadOnlyColumnCollection[str, KeyedColumnElement[Any]])r�r�r��r�zIterable[NamedColumn[Any]]�r�zIterable[ForeignKey]r��r�r��r�r�r�r;r�r�r�r�r�)r�r�r;r�r�r�r�)rx�Optional[OperatorType]r�zUnion[FromGrouping, Self]))r�r�r�r�r��named_with_columnrWr�r'rr*r�r��_is_join�_use_schema_mapr.r6r8r�r@r�rGrKr�r�r��ro_memoized_propertyrWr]r�r�r�rhrlr�rnrar�rurryr�r�r�r�r�Xs����("�N���	�"�"��#��'�&�(�(� �F�M� ���M��O��H��O��&?C���3:�"�3:�<�3:��	3:�
�3:�
�
3:�p?C��	/7�"�/7�<�/7��	/7�

�/7�d8=�1�!�1�04�1�	�1�4#�;?�	
�-�
��
�9�	
�

�
�*
.�F�
�"�"�J�#�J�
��
�@�
��	
�
3�
�
�

�
�"�"��	?��#��.
�"�"��	?��#��"
���	+��	+�)�*
�"�"�
�#�
�
���
 ��
 �
���!��!� )�"
�"�"�B�#�B��+��+��?����3�	�

��(�8(,�%�%�$�%�37�%�	�%�
�59�	,�1�	,�
&�	,�r�c�R�eZdZUdZdZded<ejd�dd��Zy)	r�z�A :class:`.FromClause` that has a name.

    Examples include tables, subqueries, CTEs, aliased tables.

    .. versionadded:: 2.0

    Trr�zsqlalchemy.sql.sqltypesc�6�t|tj�S)ayReturn 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 Database and SQL Server.

        E.g.:

        .. sourcecode:: pycon+sql

            >>> 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)
            {printsql}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`

        )rNr�
TABLEVALUEr�s r��table_valuedzNamedFromClause.table_valued)s��8!��x�':�':�;�;r�N�r�zTableValuedColumn[Any])	r�r�r�r�r�rrWr�r�r�r�r�r�r�s4�����

�I��T���2�3�<�4�<r�r�c�,�eZdZdZdZ	dZ	dZ	eZ	dZy)�SelectLabelStylezTLabel style constants that may be passed to
    :meth:`_sql.Select.set_label_style`.rrrU�N)	r�r�r�r��LABEL_STYLE_NONE�LABEL_STYLE_TABLENAME_PLUS_COL�LABEL_STYLE_DISAMBIGUATE_ONLY�LABEL_STYLE_DEFAULT�LABEL_STYLE_LEGACY_ORMr�r�r�r�r�HsE��,����4&'�"�%�N%&�!�!�F8����r�r�c���eZdZUdZdZdejfdejfdejfdejfdejfgZde	d	<d
Z
de	d<de	d<de	d<d
e	d<d
e	d<			d"									d#d�Zejd$d��Zd%d�Z	d&			d'd�Zej"d�								d(d��Zef					d)�fd�
Zd*�fd�Z						d+d�Zeddd�									d,d��Zedd�							d-d��Zeej"d�										d.d���Ze										d/d��Zd0d�Zej"d�	d1					d2d��Zejd3d ��Zejd4d!��Z�xZ S)5r1a�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`

    r6�leftr2r3r4r5rR�_traverse_internalsTr�zOptional[ColumnElement[bool]]r�Nc���tjtj|�|_tjtj|�j�|_|�,|j|j|j�|_nGtjtj|�jtj��|_||_||_
y)z�Construct 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.

        N�rx)rrrr r�ryr2�_match_primariesr3�OnClauseRoler�_asboolr4r5)r�r�r2r3r4r5s      r��__init__z
Join.__init__�s���2�$�$�� � ��
��	��%�%�� � ��
��*�,�	
�
�
�� �1�1�$�)�)�T�Z�Z�H�D�M�&�,�,��"�"�H���j��!2�!2�j�3�
�M������	r�c��d|jjt|j�|jjt|j�fzS)Nz Join object on %s(%d) and %s(%d))r�rK�idr2r�s r�rKzJoin.descriptionsD��1��I�I�!�!��t�y�y�M��J�J�"�"��t�z�z�N�	5
�
�	
r�c��t|�t|�k(xs8|jj|�xs|jj|�Sr�)�hashr�r�r2r�s  r�r�zJoin.is_derived_from%sH��
����T�
�*�
6��y�y�(�(��4�
6��z�z�)�)�*�5�	
r�c��t|�Sr�)�FromGroupingrws  r�ryzJoin.self_group.s���D�!�!r�r�c���tjj}|jjD�cgc]}|��c}|j
jD�cgc]}|��c}z}|j
|jd�|D�|j��|jd�|D��|jtj|D�cgc]}|j��c}��ycc}wcc}wcc}w)Nc3�:K�|]}|js�|���y�wr�)r�rks  r�rTz3Join._populate_column_collection.<locals>.<genexpr>As����6�H�q��
�
��H�s��c3�8K�|]}|j|f���y�wr�)�
_tq_key_label)rRrSs  r�rTz3Join._populate_column_collection.<locals>.<genexpr>Ds����(
�08��S�
�
��$����)rWr�r�r�rWr2�extend�reduce_columnsr3rV�update�	itertools�chainr�)r�r�r�r��sqlutilrWr)rSs        r�raz Join._populate_column_collection3s����.�.�)�)��>B�i�i�k�k�2J�k��1�k�2J��z�z�|�|�N
�#�!�A�|�N
�3
��	����"�"�6�H�6��
�
�
�	
�
	�'�'�(
�08�(
�	
�	����O�O�(�C�(�3�c�.�.�(�C�D�	
��3K��N
��Ds�	C(�	C-�C2c	�0���ttjt|j�t|j
���}|D�cic]}|||fi|����c}�						d�fd�}||d<t
�|�dd|i|��|j�ycc}w)Nc���t|t�r.|j�vr �|jj|�}|Syr���
isinstancerI�tabler���obj�kw�newelem�	new_fromss   �r��replacez%Join._copy_internals.<locals>.replace`�;����#�|�,����i�1G�#�C�I�I�.�C�C�C�H����r�r��clone�r�z/Union[BinaryExpression[Any], ColumnClause[Any]]r�rr�r�r�)	r`r�r�r3r�r2�super�_copy_internals�_reset_memoizations)r�r�r��
all_the_froms�fr�r�rJs      @�r�r�zJoin._copy_internalsKs������O�O��d�i�i�(��d�j�j�)�
�
�
�1>�>�
�1�Q��a��2��&�
�>�	�
	�@�	��	�/�	� ��9�
�
	���2�e�2�r�2�� � �"��+?s�Bc���t�|�|�|jj|�|jj|�yr�)r�r�r�r2�r�r�rJs  �r�r�zJoin._refresh_for_new_columnrs4���
��'��/��	�	�)�)�&�1��
�
�*�*�6�2r�c�h�t|t�r
|j}nd}|j|||��S)N)�a_subset)r�r1r2�_join_condition)r�r�r2�
left_rights    r�r�zJoin._match_primariesws4��
�d�D�!����J��J��#�#�D�%�*�#�E�Er�)r��consider_as_foreign_keysc��|j||||�}t|�dkDr|j||||�t|�dk(rGt|t�rd}nd}tjd|j�d|j�d|����t|j��dD��cgc]
\}}||k(��}	}}t|	�dk(r|	dSt|	�Scc}}w)z�Create a join condition between two tables or selectables.

        See sqlalchemy.sql.util.join_condition() for full docs.

        rrzI 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_constraintsr�r�rV�NoForeignKeysErrorrK�list�values�and_)
�cls�a�br�r��constraints�hint�x�y�crits
          r�r�zJoin._join_condition�s��� �3�3�
�x��4�
���{��a���*�*��1�k�#;�
��{��q� ��!�\�*�.��
���(�(��=�=�!�-�-��7��
�&*�+�*<�*<�*>�%?��%B�C�%B�T�Q���a��%B��C��t�9��>���7�N���;���	Ds�+C)r�c��t|t�r
|j}nd}|j||||��}t	|�S)N)r�r�r�r�)r�r1r2r�r�)r�r�r2r�r�r�s      r��	_can_joinzJoin._can_join�sJ���d�D�!����J��J��3�3����%=�	4�
���K� � r�c�R�tjj}tjt
j|�}tjt
j|�}tjt�}||fD]�}|��t|jd���D]R}|�|j|vr�	|j|�}	|	��)||j&j)|	|jf��T||urmt|jd���D]R}|�|j|vr�	|j|�}	|	��)||j&j)|	|jf��T|s��|S|S#tj$rH}
|j!|�D�chc]}|j"��ncc}w}}|
j$|vr�Yd}
~
��%d}
~
wwxYw#tj$rH}
|j!|�D�chc]}|j"��ncc}w}}|
j$|vr�Yd}
~
��d}
~
wwxYw)Nc�.�|jjSr���parent�_creation_order��fks r��<lambda>z0Join._joincond_scan_left_right.<locals>.<lambda>�s��r�y�y�8�8r��rgc�.�|jjSr�r�r�s r�r�z0Join._joincond_scan_left_right.<locals>.<lambda>�s��2�9�9�#<�#<r�)rWr�r�rrrr �collections�defaultdictr��sortedr�r��get_referentrV�NoReferenceError�find_tablesr��
table_name�
constraint�append)
r�r�r�r�r�r�r�r�r�rS�nrte�t�table_namess
             r�r�zJoin._joincond_scan_left_right�s
���>�>�*�*�����U�1�1�1�5�����U�1�1�1�5��

�#�#�D�)�	�
�q�M�D��|������8���
-�8��	�	�)A�A��!��/�/�$�/�C��?���
�
�.�5�5�s�B�I�I�6F�G�'�(�1�}� ��%�%�<��B�
1�<��I�I�-E�E� �%� �o�o�a�0����#�B�M�M�2�9�9�3��	�	�:J�K�'�(����]"�\���A�+�+�!�3;�3G�3G��3M�"N�3M�a�1�6�6�3M��"N�K�"N����+�5�� ��!��*�/�/�%�7?�7K�7K�A�7N�&O�7N�!�q�v�v�7N��&O��&O��?�?�k�9�!�$��%�sH�3E-�$G�-G�G�F'
�&G�G�H&�H!�1H
�H!�!H&c���|rDt|�D]6}|jD�chc]}|j��c}t|�k7s�4||=�8t	|�dkDrI|j�D�chc]
}t
|���}}t	|�dk(rt|�d}	|	||	i}t	|�dk7r0tjd|j�d|j�d���ycc}wcc}w)NrrzCan'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��elementsr�r`r�r�r�rV�AmbiguousForeignKeysErrorrK)
r�r�r�r�r��constr�r��dedupergs
          r�r�zJoin._joincond_trim_constraints
s���$��k�*��&+�n�n�5�n��A�H�H�n�5��,�:��$�E�*�	+��{��a��.9�.@�.@�.B�C�.B�d�e�D�k�.B�F�C��6�{�a���;�'��*��"�K��$4�5���{��q� ��/�/�
'(�m�m�Q�]�]�	D��
�!��6��Ds�C�'C"c�`�t|j|j�j|�S)a�Create a :class:`_expression.Select` from this
        :class:`_expression.Join`.

        E.g.::

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

            stmt = stmt.select()

        The above will produce a SQL string resembling:

        .. sourcecode:: sql

            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

        )r-r�r2�select_fromr�s r�r.zJoin.select0s$��$�d�i�i����,�8�8��>�>r�c��tjj}|�ret|jt
tf�r|}n:|r6t|jt�r|�d|jj��}n|}t|jt
tf�r|}n:|r6t|jt�r|�d|jj��}n|}|jj||��|jj||��}}|j|�j|j|��}|j||j|j�|j |j"��S|j%�j't(�j+d�j-|�S)N�_rr�r4r5)rWr�r�r�r�r�r1r�r�r2rur�r�r6r�r3r4r5r.�set_label_styler��	correlater�)	r�r�r;r��	left_name�
right_name�left_a�right_a�adapters	         r�ruzJoin._anonymous_fromclauseDsj���.�.�)�)����$�)�)�l�D�%9�:� �	��J�t�y�y�/�B�#'�&��$�)�)�.�.�)9� :�I� $�I��$�*�*�|�T�&:�;�!�
��J�t�z�z�?�C�$(�6��4�:�:�?�?�*;�!<�J�!%�J��	�	�/�/�Y�T�/�J��
�
�0�0�j�t�0�L��F��+�+�F�3�9�9��%�%�g�.��G��;�;��� � ����/�����Y�Y�	��
����
� ��!?�@���4����t��	
r�c	��tj|jD�cgc]"}t|j|j
���$c}�Scc}wr�)r�r�rBr3r�r2)r�r�s  r�r'zJoin._hide_fromsns?�����6:�6F�6F�
G�6F��m�A�F�F�A�G�G�,�6F�
G�
�	
��
Gs�'A	c�h�|g}||jjz|jjzSr�)r�r3r2)r��	self_lists  r�r3zJoin._from_objectsts-��'+�f�	��4�9�9�2�2�2�T�Z�Z�5M�5M�M�Mr�r~)
r�r^r2r^r3�Optional[_OnClauseArgument]r4r�r5r�r�r�r�)rxr�r�r�r��r�r�r�rr�r�r�)r�r�r2r�r�r�)
r�r�r�r�r�r�r��(Optional[AbstractSet[ColumnClause[Any]]]r�r�)r�r�r2r�r�rr�r�)
r�r�r�r�r�r�r�rr�zjcollections.defaultdict[Optional[ForeignKeyConstraint], List[Tuple[ColumnClause[Any], ColumnClause[Any]]]])
r�r�r�r�r�zDict[Any, Any]r�z
Optional[Any]r�r�r|r�)r�r�r;r�r��TODO_Anyrzr�)!r�r�r�r�r�rS�dp_clauseelement�
dp_booleanr�rr�r�rWr�rKr�ryr�rar,r�r�r��classmethodr�r�r�r�r.rur'r3�
__classcell__�rJs@r�r1r1�sM����&�N�
�"�3�3�4�	�#�4�4�5�	�&�7�7�8�	�%�0�0�1�	�"�-�-�.�3��/���H�
����+�+�
�M�
�J�15���
,�!�,�#�,�.�	,�
�,��
,�\
�"�"�
�#�
�
�15�"�-�"�	�"�
�T���.�/�
�?�
��
�3�	
�

�
�0�
�0+1�%#�'�%#�8;�%#�	
�%#�N3�
	F��	F��	F�
�		F��*.�
�*��*��*�
'�*�#
�
*�
�*��*�X�
�!��!��!�
#
�!�
�!��!�.��T���.�/�B��B�'�B��	B�
#K�B�
�
B�0��B�H� �� �� �$�	 �
#0� �
�
 �� �D?�(�T���.�/�7<�'�!�'�04�'�	�'�0�'�R
�"�"�
�#�
�

�"�"�N�#�Nr�r1c��eZdZdd�Zy)�NoInitc	���td|jj�d|jjj��d|jjj��d���)NzThe zC class is not intended to be constructed directly.  Please use the z() standalone function or the z8() method available from appropriate selectable objects.)r�rJr��lower�r��argr�s   r�r�zNoInit.__init__{sO��!����'�'����'�'�-�-�/����'�'�-�-�/�
�

�
	
r�N)rrr�r)r�r�r�r�r�r�r�rrzs��
r�rc��eZdZdZy)r�z>mark a FROM clause as being able to render directly as LATERALNr�r�r�r�r�r��s��Hr�r�c�X��eZdZUdZdZdZded<dejfdejfgZ
ded<ed	d
�							dd��Zd	d
�dd�Z
d�fd
�Z								dd�Zej"dd��Zej"dd��Zedd��Zdd�Zef					d�fd�
Zedd��Z�xZS)�AliasedReturnsRowszLBase class of aliases against tables, subqueries, and other
    selectables.TFr��elementr�rRr�Nr�c�R�|j|�}|j|fd|i|��|S)Nr�)�__new__�_init)r�r�r�r�r�s     r�r�zAliasedReturnsRows._construct�s/���k�k�#�����	�	�*�.�4�.�2�.��
r�c�D�tjtj||��|_||_||_|�^t
|t�r+|jrt|dd�}t
|t�rd}tjt|�|xsd�}||_
y)N��apply_propagate_attrsr��anon)rrr�ReturnsRowsRoler!�
_orig_namer�r�r�rIrD�safe_constructr�r�)r�r�r�s   r�r$zAliasedReturnsRows._init�s��� �'�'��!�!�:�T�
���"�������<��:�z�2��0�0��z�6�4�8���d�$4�5��D�#�2�2�2�d�8�T�^�V�L�D���	r�c�Z��t�|�|�|jj|�yr�)r�r�r!r�s  �r�r�z*AliasedReturnsRows._refresh_for_new_column�s"���
��'��/����,�,�V�4r�c�B�|jj||||��y�NrO�r!r�rps    r�raz.AliasedReturnsRows._populate_column_collection�s$��	
���8�8��'�{��	9�	
r�c�B�|j}t|t�rd}|S)N�anon_1)r�r�rDr�s  r�rKzAliasedReturnsRows.description�s ���y�y���d�,�-��D��r�c�.�|jjSr�)r!�implicit_returningr�s r�r3z%AliasedReturnsRows.implicit_returning�s���|�|�.�.�.r�c��|jS)z9Legacy for dialects that are referring to Alias.original.�r!r�s r��originalzAliasedReturnsRows.original�s���|�|�r�c�V�||jvry|jj|�S�NT)rBr!r�r�s  r�r�z"AliasedReturnsRows.is_derived_from�s(����)�)�)���|�|�+�+�J�7�7r�c�~��|j}t�|�dd|i|��||jur|j�yy)Nr�r�)r!r�r�rh)r�r�r��existing_elementrJs    �r�r�z"AliasedReturnsRows._copy_internals�sC��� �<�<��
���2�e�2�r�2��4�<�<�/��)�)�+�0r�c��|gSr�r�r�s r�r3z AliasedReturnsRows._from_objects��	���v�
r�)r�rr�r�r�rr�r[)r�rr�r�r�r�r�r�r�r�r�r�rr�)r�r�r�r��_is_from_container�_supports_derived_columnsrrSr�dp_anon_namer�rr�r$r�rarWr�rKr3r�r6r�r,r�r3rrs@r�r r �sI������ %��
��
�%�6�6�7�	�"�/�/�0�3��/��
�
#�		��	��		�
�	�
�
	��	�?C��"5�
�?�
��
�3�	
�

�
�
�"�"��#��
�"�"�/�#�/�����8�+1�,�'�,�8;�,�	
�,����r�r c��eZdZUded<y)�FromClauseAliasr�r!N�r�r�r�rr�r�r�rArA�s��
�r�rAc�J�eZdZUdZdZdZded<e		d							d	d��Zy)
r�aRepresents 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 Database).

    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`

    r�Tr�r!Nc�p�tjtj|d��j	||��S)NT)�allow_selectrr)rrrr r�)r�r�r�r;s    r��_factoryzAlias._factorys2������ � �*�4�
�
�%�T��%�
%�	&r�r�)r�r�r�r�r;r�r�r�)	r�r�r�r�r�r�rrrFr�r�r�r�r��sY���"�N��M�
���#��	&��&��&��	&�

�&��&r�r�c�D��eZdZUdZdZdZdZdZdZde	jfde	jfde	jfde	jfd	e	jfgZd
ed<dddd
�									d�fd�Zej$dd��Z	d					dd�Zddd�Z		d					dd�Z�xZS)�TableValuedAliasaAn 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.:

    .. sourcecode:: pycon+sql

        >>> from sqlalchemy import select, func
        >>> fn = func.json_array_elements_text('["one", "two", "three"]').table_valued(
        ...     "value"
        ... )
        >>> print(select(fn.c.value))
        {printsql}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!r��_tableval_type�_render_derived�_render_derived_w_typesrRr�N�r��table_value_type�joins_implicitlyc�t��t�|�||��||_|�tj|_y||_yrt)r�r$rOrr�rJ)r�r�r�rNrOrJs     �r�r$zTableValuedAlias._initKsE���	��
�j�t�
�,� 0��� �'�
���	
��"�	
�r�c�.�t||j�S)aReturn 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.:

        .. sourcecode:: pycon+sql

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

        .. seealso::

            :meth:`_functions.FunctionElement.column_valued`

        )rNrJr�s r�r�zTableValuedAlias.column\s��,!��t�':�':�;�;r�c��tj|||j|j��}|jrd|_|j
|_|S)z�Return 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.

        rMT)rHr�rJrOrKrL)r�r�r;�tvas    r�r�zTableValuedAlias.aliastsW��!1� ;� ;���!�0�0�!�2�2�	!<�!
�����"&�C��*.�*F�*F�C�'��
r�c�8�|j|��}d|_|S)z�Return a new :class:`_sql.TableValuedAlias` with the lateral flag
        set, so that it renders as LATERAL.

        .. seealso::

            :func:`_expression.lateral`

        r�T)r�r�)r�r�rSs   r�r�zTableValuedAlias.lateral�s ���j�j�d�j�#������
r�c��tj|j||j|j��}d|_||_|S)a�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.:

        .. sourcecode:: pycon+sql

            >>> print(
            ...     select(
            ...         func.unnest(array(["one", "two", "three"]))
            ...         .table_valued("x", with_ordinality="o")
            ...         .render_derived()
            ...     )
            ... )
            {printsql}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):

        .. sourcecode:: pycon+sql

            >>> 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)
            ...     )
            ... )
            {printsql}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.

        rMT)rHr�r!rJrOrKrL)r�r��
with_types�	new_aliass    r��render_derivedzTableValuedAlias.render_derived�sO��n'7�&A�&A��L�L��!�0�0�!�2�2�	'B�'
�	�%)�	�!�,6�	�)��r�)
r�rr�r�rNzOptional[TableValueType]rOr�r�r�r�r�)r�r�r;r�r�rHr�r�)r�r�rVr�r�rH)r�r�r�r�r�r>rKrLrOrSrr?�dp_typerr�rr$rA�memoized_attributer�r�r�rXrrs@r�rHrH"s-����2*�N� $���O�#����
�%�6�6�7�	�"�/�/�0�	�,�4�4�5�	�-�8�8�9�	"�$5�$@�$@�A�3��/��#�59�!&�

��
��	
�
3�
��

�
�
�"�#�#�<�$�<�08=��!��04��	��.�#� �?��?��?�
�	?r�rHc�<�eZdZdZdZdZdZe	d					dd��Zy)r�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.

    .. seealso::

        :ref:`tutorial_lateral_correlation` -  overview of usage.

    r�TNc�n�tjtj|d��j	|��S)NT)�explicit_subqueryr�)rrrr r��r�r�r�s   r�rFzLateral._factory�s0������ � �*��
�
�'�t�'�
�	r�r�)r�z&Union[SelectBase, _FromClauseArgument]r�r�r�r�)	r�r�r�r�r�r�r�rrFr�r�r�r�r��sK��� �N��K��M��#��:����
�	��r�r�c���eZdZUdZdZejdejfdejfgzZde	d<e
		d
									dd��Zejd	�ddd
�									d�fd��Zdd�Z�xZS)r?aIRepresent 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.

    .. seealso::

        :func:`_expression.tablesample`

    r@r=r>rRr�Nc�n�tjtj|�j	|||��S)N�r�r>)rrrr r@)r�r�r=r�r>s     r�rFzTableSample._factorys7������ 4� 4�j�A�M�M��4�d�N�
�	
r�zsqlalchemy.sql.functionsrac����|�J�tjj}t||j�s|j
j
|�}||_||_t�|�)||��yrt)rWr��
sql_functionsr�r|�func�systemr=r>r�r$)r�r�r�r=r>�	functionsrJs      �r�r$zTableSample._initsb����#�#�#��N�N�0�0�	��(�I�$6�$6�7� �~�~�,�,�X�6�H�'/��
���	�
��
�j�t�
�,r�c��|jSr�)r=r�s r��_get_methodzTableSample._get_method1s���}�}�r�r�)
r�r^r=r�r�r�r>r�r�r?)
r�rr�r�r=r�r>r�r�r�)r�z
Function[Any])r�r�r�r�r�r r�rSrrrrFrWr�r$rhrrs@r�r?r?�s�����#�N�	�.�.�
�*�;�;�<�
�&�7�7�8�
�	
��/���
#�;?�	
�'�	
�.�	
��		
�
9�	
�
�
	
��	
��T���3�4�
#�;?�
-��-��	-�
.�-�9�
-�
�-�5�-�"r�r?c���eZdZUdZdZejdejfdejfdejfdejfgze
jzejzZded<d	ed
<e		d							dd
��Zdddddddd�																	d�fd�Z								dd�Zddd�Zdd�Z				dd�Zdd�Z�xZS)�CTEaURepresent 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�nestingrRr��HasCTEr!NFc�l�tjtj|�j	||��S)z�Return a new :class:`_expression.CTE`,
        or Common Table Expression instance.

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

        )r�rn)rrr�
HasCTERolerk)r�r�r�rns    r�rFzCTE._factory_s5������ 0� 0�*�=�A�A���B�
�	
r�)r�rnrorlrmr�rc���||_||_||_||_|r||_|r||_t�	|�||��yrt)rnrorlrmr�rr�r$)
r�r�r�rnrorlrmr�rrJs
         �r�r$z	CTE._initpsE���#������$���"����&�D�N��&�D�N�
��
�j�t�
�,r�c��|j� |jj||||��y|jj||||��yr.)rlr�r!rps    r�razCTE._populate_column_collection�sW���?�?�&��O�O�?�?���'�)�	
@�
�
�L�L�<�<���'�)�	
=�
r�c	��tj|j||j|j||j
|j��S)a2Return 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`

        )r�rnrorlr�r)rjr�r!rnror�rr:s   r�r�z	CTE.alias�sC���~�~��L�L���n�n��L�L���n�n��n�n��
�	
r�c	� �t|j�sJd|j�d���tj|jj|�|j
|j|j||j|j��S)a�Return a new :class:`_expression.CTE` with a SQL ``UNION``
        of the original CTE against the given selectables provided
        as positional arguments.

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

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

        .. seealso::

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

        �
CTE element fz does not support union()�r�rnrormr�r)
r&r!rjr�rr�rnror�rrEs  r�rz	CTE.union�s���#��L�L�
�	C�
�4�<�<�.�(A�B�	C�
��~�~��D�L�L����&�����n�n��L�L���n�n��n�n��
�	
r�c	� �t|j�sJd|j�d���tj|jj|�|j
|j|j||j|j��S)a�Return a new :class:`_expression.CTE` with a SQL ``UNION ALL``
        of the original CTE against the given selectables provided
        as positional arguments.

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

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

        .. seealso::

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

        rwz does not support union_all()rx)
r&r!rjr��	union_allr�rnror�rrEs  r�rzz
CTE.union_all�s���$#��L�L�
�	G�
�4�<�<�.�(E�F�	G�
��~�~�"�D�L�L�"�"�E�*�����n�n��L�L���n�n��n�n��
�	
r�c�6�|j�|jS|S)z�
        A recursive CTE is updated to attach the recursive part.
        Updated CTEs should still refer to the original CTE.
        This function returns this reference identifier.
        )rmr�s r��_get_reference_ctezCTE._get_reference_cte�s��"&���!;�t�~�~�E��Er�r�)r�rpr�r�rnr�r�rj)r�r}r�r�rnr�ror�rl�
Optional[CTE]rmr}r��Optional[Tuple[()]]rr~r�r�r�)r�r�r;r�r�rj)rFz(_SelectStatementForCompoundArgument[Any]r�rj)r�rj)r�r�r�r�r�r r�rSrrr�r�r
rrrrFr$rar�rrzr|rrs@r�rjrj5s�����$�N�	�.�.�
�,�=�=�>�
�+�<�<�=�
�+�6�6�7�
�)�4�4�5�	
�	
��
6�
6�	7��
6�
6�	7��/�
��O��#��	
��
��
��	
�


�
��
�(#���$(�#'�)-�)-�-��-��	-�
�-��
-�"�-�!�-�'�-�'�-�
�-�.�?����3�	�

��*
�0
�:
�>�
�	�
�@Fr�rjc��eZdZUded<y)�_CTEOptsr�roNrBr�r�r�r�r��s��
�Mr�r�c�H�eZdZUded<	ded<	ded<	ded<	ded<y	)
�_ColumnsPlusNamesr��required_label_name�	proxy_key�fallback_label_name�%Union[ColumnElement[Any], TextClause]r�r��repeatedNrBr�r�r�r�r��s@��&�&��
���'�&��
2�1���N�r�r�c�6�eZdZUdZeZded<	d					dd�Zy)�SelectsRowszvSub-base of ReturnsRows for elements that deliver rows
    directly, namely SELECT and INSERT/UPDATE/DELETE..RETURNINGr��_label_styleNc
���|�|j}tj|j�}i}g}|j}|jt
u}|jtu}d}	|D�]}
d}|
jsdx}x}
}n�|r2tr
t|
�sJ�dx}}
|
jxs|
j}n�tr
t|
�sJ�|r|
jx}
x}}n|
jx}}d}
|�t|
j}|�`|
j|v}|
||
j<dx}}
|r0|r|
j|	�}|	dz
}	n*|
j|	�}|	dz
}	n|
j}n|x}
x}}|��tr
t|
�sJ�||vr�t!||�t!|
�k7r}|r|
j"x}
}n|
jx}
}|rV|
|vrRt!||
�t!|
�k(sJ�|r|
j|	�x}
}|	dz
}	n|
j|	�x}
}|	dz
}	d}nC|
||
<n=|r;|r|
j|	�x}
}|	dz
}	n|
j|	�x}
}|	dz
}	d}n|
||<|t%|
||
�||
|����|S)acGenerate 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.

        NrFT)r��SelectState�_column_naming_conventionr�r�r�r��_render_label_in_columns_clauserr%�_non_anon_label�_anon_name_label�	_tq_label�_expression_label�_dedupe_anon_tq_label_idx�_dedupe_anon_label_idxr��_anon_tq_labelr�)r��anon_for_dupe_key�cols�key_naming_convention�names�result�
result_append�table_qualified�label_style_none�dedupe_hashrWr��effective_namer�r��
expr_labels                r��_generate_columns_plus_namesz(SelectsRows._generate_columns_plus_names%	sM���<��-�-�D� +� E� E����!
����*,���
�
�
��+�+�/M�M���,�,�0@�@�����A��H��4�4�����!4�7J�"� �,�Q�/�/�/�7;�;��!4�&'�&7�&7�&M�1�;M�;M�#� �,�Q�/�/�/�"����$�'�$�.�+�<=�;L�;L�L�N�%8�*.�'�!�)�"#�!4�!4�J�!�)�#$�#5�#5��#>��45��a�0�0�1�?C�C��)<�#� /�$%�$?�$?��$L�!4�!,�q� 0��67�6N�6N�$/�7"� 3�!,�q� 0��23�2D�2D�/�'�'�+�'�n�/��)� �,�Q�/�/�/�!�U�*��E�.�1�2�d�1�g�=�+� !� 0� 0��/�2E�
!"� 2� 2��/�2E�-�1D��1M�$(��.A�(B�#C�t�A�w�#N�N�#N� /�$%�$?�$?��$L�!"� 3�6I�!,�q� 0��%&�$<�$<�[�$I�!"� 3�6I�!,�q� 0��'+�H�9:�E�"5�6�*�+� !� ;� ;�K� H��/�2E�(�1�,�K�!"� 8� 8�� E��/�2E�(�1�,�K�#'��,-�E�.�)��!�'�)�!�,�'����
�k�~�
r�r�)r�r�r�zOptional[_SelectIterable]r�zList[_ColumnsPlusNames])r�r�r�r�r�r�rr�r�r�r�r�r�	s?��C�&6�L�"�5�
+/�e��e�(�e�
!�	er�r�c��eZdZUdZdej
fdejfgZded<dZ	ded<dZ
ded<ed	d
�dd��Z			d							dd
�Z
y)rpz3Mixin that declares a class to include CTE support.�_independent_ctes�_independent_ctes_optsrR�_has_ctes_traverse_internalsr�zTuple[CTE, ...]zTuple[_CTEOpts, ...]F��	nest_herec���t|�}|D]R}tjtj|�}|xj
|fz
c_|xj|fz
c_�T|S)a�Add one or more :class:`_sql.CTE` constructs to this statement.

        This method will associate the given :class:`_sql.CTE` constructs with
        the parent statement such that they will each be unconditionally
        rendered in the WITH clause of the final statement, even if not
        referenced elsewhere within the statement or any sub-selects.

        The optional :paramref:`.HasCTE.add_cte.nest_here` parameter when set
        to True will have the effect that each given :class:`_sql.CTE` will
        render in a WITH clause rendered directly along with this statement,
        rather than being moved to the top of the ultimate rendered statement,
        even if this statement is rendered as a subquery within a larger
        statement.

        This method has two general uses. One is to embed CTE statements that
        serve some purpose without being referenced explicitly, such as 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.  The other is to provide control over the exact placement
        of a particular series of CTE constructs that should remain rendered
        directly in terms of a particular statement that may be nested in a
        larger statement.

        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:

        .. sourcecode:: sql

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

        .. sourcecode:: sql

            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

        :param \*ctes: zero or more :class:`.CTE` constructs.

         .. versionchanged:: 2.0  Multiple CTE instances are accepted

        :param nest_here: if True, the given CTE or CTEs will be rendered
         as though they specified the :paramref:`.HasCTE.cte.nesting` flag
         to ``True`` when they were added to this :class:`.HasCTE`.
         Assuming the given CTEs are not referenced in an outer-enclosing
         statement as well, the CTEs given should render at the level of
         this statement when this flag is given.

         .. versionadded:: 2.0

         .. seealso::

            :paramref:`.HasCTE.cte.nesting`


        )r�rrr�	IsCTERoler�r�)r�r��ctes�optrks     r��add_ctezHasCTE.add_cte�	s\��J�y�!���C��"�"�5�?�?�C�8�C��"�"�s�f�,�"��'�'�C�6�1�'���r�Nc�4�tj||||��S)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.

        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
         statement in which it is referenced.   For more complex scenarios,
         the :meth:`.HasCTE.add_cte` method using the
         :paramref:`.HasCTE.add_cte.nest_here`
         parameter may also be used to more carefully
         control the exact placement of a particular CTE.

         .. versionadded:: 1.4.24

         .. seealso::

            :meth:`.HasCTE.add_cte`

        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:

        .. sourcecode:: sql

            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

        The same CTE can be set up using the :meth:`.HasCTE.add_cte` method
        as follows (SQLAlchemy 2.0 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 CTEs takes ascendency locally
            # over the CTEs at a higher level
            value_b = (
                select(value_a_nested.c.n)
                .add_cte(value_a_nested, nest_here=True)
                .cte("value_b")
            )

            value_ab = select(value_a.c.n.label("a"), value_b.c.n.label("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:

        .. sourcecode:: sql

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

        )r�rnro)rjr�)r�r�rnros    r�rkz
HasCTE.cteD
s$��P	�~�~��t�y�'��
�	
r��r�rjr�r�r�r[r~)r�r�rnr�ror�r�rj)r�r�r�r�rS�dp_clauseelement_list�dp_plain_objr�rr�r�r4r�rkr�r�r�rprp�	s���=�
�/�E�E�F�	!�#4�#A�#A�B�<� �"8��
*,���+�35��0�5��49�i��i�Z#���	j
��j
��j
��	j
�


�j
r�rpc�|�eZdZUdZdZdZdZded<e	d					dd��Z	e
jdd	�d
d
��Zy)�Subquerya�Represent a subquery of a SELECT.

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

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

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

    �subqueryT�
SelectBaser!Nc�j�tjtj|�j	|��S)z#Return a :class:`.Subquery` object.r�)rrr�SelectStatementRoler�r^s   r�rFzSubquery._factory�s.������%�%�z�
�
�(��(�
�	r�r�axThe :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�\�|jjt�j�Sr�)r!rr��scalar_subqueryr�s r��	as_scalarzSubquery.as_scalar�s#���|�|�+�+�,<�=�M�M�O�Or�r�)r�r�r�r�r�r��r��ScalarSelect[Any])
r�r�r�r�r��_is_subqueryr�rrrFrWr�r�r�r�r�r�r�qst���8 �N��L��M�
���;?��#��+8��	�����T�_�_�
�	?�	�P�	�Pr�r�c�Z�eZdZUdZdej
fgZded<ded<dd�Ze	j		dd��Ze	jdd��Ze
dd	��Ze
dd
��Zdd�Z	d					dd
�Zdd�Ze	jdd��Ze	jdd��Zdd�Zdd�Zer
	d 			d!d�Zyy)"r�z%Represent a grouping of a FROM clauser!rRr�r�c�V�tjtj|�|_yr�)rrrr r!�r�r!s  r�r�zFromGrouping.__init__�s�� �'�'��(<�(<�g�F��r�c�.�|jjSr��r!r�r�s r�r�zFromGrouping.columns�s���|�|�#�#�#r�c�.�|jjSr�r�r�s r�rWzFromGrouping.c�s���|�|�#�#�#r�c�.�|jjSr�)r!r�r�s r�r�zFromGrouping.primary_key�����|�|�'�'�'r�c�.�|jjSr�)r!r�r�s r�r�zFromGrouping.foreign_keys�s���|�|�(�(�(r�c�8�|jj|�Sr�)r!r�r�s  r�r�zFromGrouping.is_derived_from�s���|�|�+�+�J�7�7r�Nc�N�t|jj||���S)Nrr)�NamedFromGroupingr!r�r:s   r�r�zFromGrouping.alias�s#��!����!3�!3��D�!3�!I�J�Jr�c�L�t|jjdi|���Sr&)r�r!ru)r�r�s  r�ruz"FromGrouping._anonymous_fromclause�s"���>�D�L�L�>�>�D��D�E�Er�c�.�|jjSr�)r!r'r�s r�r'zFromGrouping._hide_froms�r�r�c�.�|jjSr��r!r3r�s r�r3zFromGrouping._from_objects�����|�|�)�)�)r�c��d|jiS�Nr!r5r�s r��__getstate__zFromGrouping.__getstate__�s���4�<�<�(�(r�c��|d|_yr�r5�r��states  r��__setstate__zFromGrouping.__setstate__�s���Y�'��r�c��yr�r�rws  r�ryzFromGrouping.self_group����r�)r!r�r�r�r�r�r�)r�r�r;r�r�r�)r�rr�r�rzr�)r��Dict[str, FromClause])r�r�r�r�r��rxr�r�r[)r�r�r�r�rSrr�rr�rWr�r�rWr�r�r�r�r�rur'r3r�r�rryr�r�r�r�r��s+��/�
�%�6�6�7�3��/����G�
�"�"�$�	?�$�#�$�

�"�"�$�#�$��(��(��)��)�8�8=�K�!�K�04�K�	�K�
F�
�"�"�(�#�(�
�"�"�*�#�*�)�(��59�	�1�	�
�	�r�r�c�,�eZdZdZdZer
	d			dd�Zyy)r�zLrepresent a grouping of a named FROM clause

    .. versionadded:: 2.0

    TNc��yr�r�rws  r�ryzNamedFromGrouping.self_group�r�r�r�r�)r�r�r�r�r�rryr�r�r�r�r��s0����M��59�	�1�	�
�	�r�r�c���eZdZUdZdZdejfdejfdejfgZde	d<dZ
d	e	d
<dZ	ejdd��Zd�fd
�Zer(ej"		dd��Zej"dd��Zdd�Zdd�Zejdd��Zdd�Zej0d�dd��Zej0d�d d��Zej0d�d!d��Zej"d"d��Z�xZS)#�TableClausea.Represents a minimal "table" construct.

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

        from sqlalchemy import table, column

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

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

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

    r�r�r�r*rRr�Tr�fullnameFc��y)z4No PK or default support so no autoincrement column.Nr�r�s r��_autoincrement_columnz!TableClause._autoincrement_column/s��r�c���t�|��||_t�|_t�|_t�|_|D]}|j|��|jdd�}|�||_|j�!|j�d|j��|_n|j|_|r!tjdt|�z��y)Nr*�.zUnsupported argument(s): %s)r�r�r�r=r)r;r�r`r��
append_columnrfr*r�rV�
ArgumentErrorr�)r�r�r�r�rWr*rJs      �r�r�zTableClause.__init__4s����
������	�.�0��
�$�;����E����A����q�!������$�'���� �D�K��;�;�"�'+�{�{�D�I�I�>�D�M� �I�I�D�M�
��#�#�$A�D��H�$L�M�M�r�c��yr�r�r�s r�r�zTableClause.columnsIs	��@Cr�c��yr�r�r�s r�rWz
TableClause.cNs��ILr�c�j�|j�|jdz|jzS|jS)Nr�)r*r�r�s r��__str__zTableClause.__str__Qs.���;�;�"��;�;��$�t�y�y�0�0��9�9�r�c��yr�r�r�s  r�r�z#TableClause._refresh_for_new_columnWs��r�c��|jSr�r�r�s r�rKzTableClause.descriptionZs���y�y�r�c��|j}|�*||ur&tjd|j�d|�d���|jj|�||_y)Nzcolumn object 'z' already assigned to table '�')r�rVr�rgr)�add)r�rW�existings   r�r�zTableClause.append_column^sT���7�7����H�D�$8��#�#��5�5�(�$��
�
	
�
�
���!����r�zsqlalchemy.sql.dmlc�T�tjjj|�S)z�Generate an :class:`_sql.Insert` construct against this
        :class:`_expression.TableClause`.

        E.g.::

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

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

        )rWr��sql_dml�Insertr�s r��insertzTableClause.insertis���~�~�%�%�,�,�T�2�2r�c�T�tjjj|�S)aGenerate 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.

        )rWr�r�rvr�s r�r�zTableClause.updatexs$���~�~�%�%�,�,��
�	
r�c�T�tjjj|�S)z�Generate 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.

        )rWr�r�rur�s r��deletezTableClause.delete�s���~�~�%�%�,�,�T�2�2r�c��|gSr�r�r�s r�r3zTableClause._from_objects�r<r�)r�zOptional[ColumnClause[Any]])r�rr��ColumnClause[Any]r�r)r�z0ReadOnlyColumnCollection[str, ColumnClause[Any]]r�r�)rWr�r�r�)r�zutil.preloaded.sql_dml.Insert)r�rv)r�rur�)r�r�r�r�r�rS�)dp_fromclause_canonical_column_collection�	dp_stringr�r�	_is_tabler3rWr�r�r�rr�r�rWr�r�rKr�r�r�r�r�r3rrs@r�r�r��sp����<�N�
��G�G�	
�
�"�,�,�-�	�$�.�.�/�
3��/���I��M���=�
������N�&�	
�	&�	&�	C�
=�	C�
'�	C�
�	&�	&�L�
'�L��
�
������	��T���-�.�3�/�3��T���-�.�

�/�

��T���-�.�3�/�3�
�"�"��#�r�r��ForUpdateArgc� �eZdZUdejfdej
fdej
fdej
fdej
fgZded<ded<d	ed<d	ed<d	ed<e				dd
��Z	dd�Z
dd�Zdd
�Zdddddd�									dd�Z
y)r��of�nowait�read�skip_locked�	key_sharerRr�z!Optional[Sequence[ClauseElement]]r�c�v�t|t�r|S|dvry|dur
t�Stditd|���S)Nr�T�Dict[str, Any]r�)r�r�r)r��with_for_updates  r��_from_argumentzForUpdateArg._from_argument�sE���o�|�4�"�"�
�
�
-��
��
$��>�!��J�$�'7��"I�J�Jr�c�.�t|t�xr�|j|jk(xri|j|jk(xrN|j|jk(xr3|j
|j
k(xr|j|juSr�)r�r�r�r�r�rr�rEs  r��__eq__zForUpdateArg.__eq__�s����u�l�+�
$�������+�
$��
�
�d�i�i�'�
$��!�!�T�%5�%5�5�
$����4�>�>�1�	
$�
���D�G�G�#�
	
r�c�&�|j|�Sr�)rrEs  r��__ne__zForUpdateArg.__ne__�s���;�;�u�%�%�%r�c��t|�Sr�)r�r�s r��__hash__zForUpdateArg.__hash__�s���$�x�r�FN�r�r�r�r�rc���||_||_||_||_|�Kt	j
|�D�cgc]&}t
jtj|���(c}|_
yd|_
ycc}w)zZRepresents arguments specified to
        :meth:`_expression.Select.for_update`.

        N)r�r�r�rrW�to_listrrr�ColumnsClauseRoler�)r�r�r�r�r�r�elems       r�r�zForUpdateArg.__init__�sq�������	�&���"���
�>�!�L�L��,��,�D�� � ��!8�!8�$�?�,��D�G�
�D�G��s�+A2)r�ForUpdateParameterr��Optional[ForUpdateArg])rFrr�r�)r��int)
r�r�r�r�r��Optional[_ForUpdateOfArgument]r�r�rr�)r�r�r�rSr�rr�rrrrrr
r�r�r�r�r�r��s���	
� �6�6�7�	�$�/�/�0�	�"�-�-�.�	�)�4�4�5�	�'�2�2�3�3��/��	*�)��L�
�J����
K�0�
K�	�
K��
K�
�&����-1�!������	�

+���
��r�c�\��eZdZUdZdZdZded<ded<dejfdejfd	ejfd
ejfgZded<d
dd�					d�fd�Z
edd��Zeddd��Zeddd��Zedd��Zdd�Z								d d�Zej.d!d��Z�xZS)"�Valuesz�Represent 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

    r�r��%Tuple[Sequence[Tuple[Any, ...]], ...]�_datar��_unnamed�_column_argsr��
literal_bindsrRr�NF)r�rc����t�|��||_|�,d|_t	j
t
|�d�|_nd|_||_||_|j|_	y)NTr(F)
r�r�rrrDr+r�r�rr�)r�r�rr�rJs    �r�r�zValues.__init__�sa���	����#����<� �D�M�(�7�7��4��&�I�D�I�!�D�M��D�I�*���%)�]�]�!2��r�c�T�|jD�cgc]}|j��c}Scc}wr��r�type�r�rSs  r��
_column_typeszValues._column_types

�&��$(�$5�$5�6�$5�S����$5�6�6��6��%c�x�|� tjt|�d�}n|}||_d|_d|_|S)aYReturn 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`

        r(TF)rDr+r�r�r�r)r�r�r;�
non_none_names    r�r�zValues.alias
s?��$�<�,�;�;�B�t�H�f�M�M� �M�!��	�!%�����
��r�c�R�|�
|j}n|}d|_||_d|_|S)z�Return a new :class:`_expression.Values` with the lateral flag set,
        so that
        it renders as LATERAL.

        .. seealso::

            :func:`_expression.lateral`

        TF)r�r�r)r�r�r$s   r�r�zValues.lateral-
s2���<� �I�I�M� �M����!��	���
��r�c�2�|xj|fz
c_|S)ajReturn 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.

        )r)r�r�s  r��datazValues.dataD
s��	
�
�
�v�i��
��r�c�X�t|j|j|j�S)z�Returns a scalar ``VALUES`` construct that can be used as a
        COLUMN element in a statement.

        .. versionadded:: 2.0.0b4

        )�ScalarValuesrrrr�s r��
scalar_valueszValues.scalar_valuesV
s#���D�-�-�t�z�z�4�;M�;M�N�Nr�c���|jD]\}|j�&|j|ur|j|||��\}}n|j�|j	|�||_�^yr.)rr�rQr�r�)r�r�r�r�rWrs      r�raz"Values._populate_column_collection_
sg���"�"�A��w�w�"�q�w�w�d�':��}�}��k��%����1��%�%�'��K�K��N��A�G�#r�c��|gSr�r�r�s r�r3zValues._from_objectsr
r<r�)r�r�r�r�rr��r�zList[TypeEngine[Any]]r�)r�r�r;r�r�r[r�r�)r�zSequence[Tuple[Any, ...]]r�r[�r�r)r�r�)r�r�r�r�r�rrrSr��dp_dml_multi_valuesr�rr�r�r�r r4r�r�r'r*rarWr�r3rrs@r�rr�s/�����N�35�E�0�5��N�	�*�@�@�A�	�#�7�7�8�	�"�,�,�-�	�+�6�6�7�	3��/��#�#�	3�#�3��3��	3�$�7��7�����6����,����"O��?����3�	�

��&
�"�"��#�r�rc����eZdZUdZdZdejfdejfdejfgZ	de
d<						d�fd�Zed
d	��Z
dd
�Zer
	d			dd�Z�xZS�xZS)r)a{Represent a scalar ``VALUES`` construct that can be used as a
    COLUMN element in a statement.

    The :class:`_expression.ScalarValues` object is created from the
    :meth:`_expression.Values.scalar_values` method. It's also
    automatically generated when a :class:`_expression.Values` is used in
    an ``IN`` or ``NOT IN`` condition.

    .. versionadded:: 2.0.0b4

    r*rrrrRr�c�L��t�|��||_||_||_yr�)r�r�rrr)r�r�r'rrJs    �r�r�zScalarValues.__init__�
s'���	����#�����
�*��r�c�T�|jD�cgc]}|j��c}Scc}wr�rrs  r�r zScalarValues._column_types�
r!r"c��|Sr�r�r�s r��__clause_element__zScalarValues.__clause_element__�
����r�c��yr�r�rws  r�ryzScalarValues.self_group�
r�r�)r�zSequence[ColumnClause[Any]]r'rrr�r-r.r�r�)r�r�r�r�r�rSr�r/rr�rr�r�r r4rryrrs@r�r)r)w
s����
�%�N�
�*�@�@�A�	�#�7�7�8�	�+�6�6�7�3��/��	+�,�	+�4�	+��		+��7��7���59�	�1�	�
�	�r�r)c��eZdZUdZdZdZeZded<dd�Z	e
j		d d��Zdd�											d!d	�Z
e
jd"d
��Ze		d#d��Zee
j"dd
�d$d���Ze		d$d��Zd%d�Zd&d�Ze
j"dd�d'd��Zej0d(d��Zd)d�Ze
j"dd�d*d��Zd+d�Zd*d�Zd,d�Zd-d.d�Zd-d/d�Z d0d�Z!	d1					d2d�Z"y)3r�z�Base class for SELECT statements.


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


    Tr�r�c�$�|j�yr�)r�r�s  r�r�z"SelectBase._refresh_for_new_column�
s��� � �"r�c��t��)a$A :class:`_expression.ColumnCollection`
        representing the columns that
        this SELECT statement or similar construct returns in its result set.

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

        .. note::

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

        .. seealso::

            :attr:`_sql.Select.selected_columns`

        .. versionadded:: 1.4

        r�r�s r��selected_columnszSelectBase.selected_columns�
s
��<"�#�#r�N��proxy_compound_columnsc��t��r�r��r�r�r�r�r�r<s      r�r�z.SelectBase._generate_fromclause_column_proxies�
s
��"�#�#r�c��t��)aA 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`

        r�r�s r�r�z SelectBase._all_selected_columns�
s
��"�#�#r�c�6�|jj�S)afA :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:r^r�s r�r�zSelectBase.exported_columns�
s��2�$�$�0�0�2�2r�r�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�.�|jjSr�)�_implicit_subqueryr�r�s r�rWzSelectBase.cs���&�&�.�.�.r�c��|jSr�rYr�s r�r�zSelectBase.columns(s
���v�v�
r�c��t��)zX
        Retrieve the current label style.

        Implemented by subclasses.

        r�r�s r��get_label_stylezSelectBase.get_label_style.r�r�c��t��)zeReturn a new selectable with the specified label style.

        Implemented by subclasses.

        r��r��styles  r�rzSelectBase.set_label_style7r�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�:�|jj|i|��Sr�)rBr.rs   r�r.zSelectBase.select@s"��.�t�&�&�-�-�s�9�b�9�9r�c�"�|j�Sr��r�r�s r�rBzSelectBase._implicit_subqueryLs���}�}��r�c��t��r�r�r�s r��_scalar_typezSelectBase._scalar_typePr�r�z�The :meth:`_expression.SelectBase.as_scalar` method is deprecated and will be removed in a future release.  Please refer to :meth:`_expression.SelectBase.scalar_subquery`.c�"�|j�Sr�)r�r�s r�r�zSelectBase.as_scalarSs���#�#�%�%r�c��t|�S)aaReturn 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

        )�Existsr�s r��existszSelectBase.exists]s���d�|�r�c�f�|jtur|jt�}t|�S)aXReturn 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

        )r�r�r�ScalarSelectr�s r�r�zSelectBase.scalar_subqueryns/��0���$4�4��'�'�(8�9�D��D�!�!r�c�@�|j�j|�S)z�Return a 'scalar' representation of this selectable, embedded as a
        subquery with a label.

        .. seealso::

            :meth:`_expression.SelectBase.scalar_subquery`.

        )r��labelr�s  r�rUzSelectBase.label�s���#�#�%�+�+�D�1�1r�c�.�tj||�S)r�)r�rFr�s  r�r�zSelectBase.lateral�s������d�+�+r�c�L�tj|j�|��S)aReturn 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:

        .. sourcecode:: sql

            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:

        .. sourcecode:: sql

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

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

        .. versionadded:: 1.4

        r�)r�r��_ensure_disambiguated_namesr�s  r�r�zSelectBase.subquery�s+��X�"�"��,�,�.�T�#�
�	
r�c��t��)ztEnsure that the names generated by this selectbase will be
        disambiguated in some way, if possible.

        r�r�s r�rXz&SelectBase._ensure_disambiguated_names�s
��"�#�#r�c�&�|j|��S)a.Return a named subquery against this
        :class:`_expression.SelectBase`.

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

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

        r�rKr:s   r�r�zSelectBase.alias�s��"�}�}�$�}�'�'r�r��r�z)ColumnCollection[str, ColumnElement[Any]]�r�r�r�r�r�r;r�r�r<�0Optional[Iterable[Sequence[ColumnElement[Any]]]]r�r�r�)r�z1ReadOnlyColumnCollection[str, ColumnElement[Any]]r��r�r��rHr�r�r[)rrr�rr�r})r�r��r�zTypeEngine[Any]r�)r�rP)r�r�r�z
Label[Any]r�r�)r�r�r�r��r�r[r�)r�r�r;r�r�r�)#r�r�r�r�r��	is_selectr�r�rr�rWr�r:r�r�r�r�r�rWr�rErr.rArZrBrMr�rQr�rUr�r�rXr�r�r�r�r�r��
s�����O��I�%5�L�"�5�#�
�"�"�$�	2�$�#�$�P
�$��$�@�$��	$�
3�$�!
�$�
�$�
�"�"�$�#�$��3�	:�3��3�4��T�_�_�
�		��/���/���	?����
$�$��T�_�_�
�	2��:��:��#�#��$��$��T�_�_�
�	:��&��&��""�:	2�,�.
�`$�8=�(�!�(�04�(�	�(r�r��_SB)�boundc�Z�eZdZUdZdZdejfgejzZ	de
d<dZde
d<dd�Zdd	�Z
dd
�Z				dd�Zedd��Zddd�Zerdd�Zd
d�											dd�Zej.d d��Zej.d!d��Zej.d"d��Zdd�d#d�Zy
)$�SelectStatementGroupingz�Represent 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!rRr�Trcc�r�tttjtj
|��|_yr�)rrcrrrr�r!r�s  r�r�z SelectStatementGrouping.__init__s&�����!�!�%�";�";�W�E�
��r�c�l�|jj�}||jurt|�S|Sr�)r!rXrf)r��new_elements  r�rXz3SelectStatementGrouping._ensure_disambiguated_names	s0���l�l�>�>�@���d�l�l�*�*�;�7�7��Kr�c�6�|jj�Sr�)r!rEr�s r�rEz'SelectStatementGrouping.get_label_styles���|�|�+�+�-�-r�c�J�t|jj|��Sr�)rfr!r)r��label_styles  r�rz'SelectStatementGrouping.set_label_styles#��'��L�L�(�(��5�
�	
r�c��|jSr�r5r�s r��select_statementz(SelectStatementGrouping.select_statements���|�|�r�Nc��|Sr�r�rws  r�ryz"SelectStatementGrouping.self_groupr5r�c��yr�r�r�s r��_ungroupz SelectStatementGrouping._ungroup#s��3r�r;c�D�|jj|||||��y)N�r<r�r�r/r>s      r�r�z;SelectStatementGrouping._generate_fromclause_column_proxies*s*��	
���8�8���#9�#�%�	9�	
r�c�.�|jjSr�)r!r�r�s r�r�z-SelectStatementGrouping._all_selected_columns=s���|�|�1�1�1r�c�.�|jjS)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:r�s r�r:z(SelectStatementGrouping.selected_columnsAs���|�|�,�,�,r�c�.�|jjSr�r�r�s r�r3z%SelectStatementGrouping._from_objectsQr�r�Fr�c��t�r�r�)r�r�r�s   r�r�zSelectStatementGrouping.add_cteUs��!�!r�)r!rcr�r�)r��SelectStatementGrouping[_SB]r^)rmr�r�ry)r�rcr�r�r\r�r[r�r�)r�r�r�r�r�rSrr+�%_clone_annotations_traverse_internalsr�r�_is_select_containerr�rXrErr�roryrrrr�rWr�r�r:r3r�r�r�r�rfrf�s,���1�N�	�%�6�6�7�3� �F�F�3G��/�G� ��
�L�
�
�.�
�+�
�	%�
�������&� 
�
��
�@�
��	
�
3�
�!
�
�
�
�&
�"�"�2�#�2�
�"�"�
-�#�
-�
�"�"�*�#�*�5:�"r�rfc��eZdZUdZdZded<dZded<dZded<dZded	<dZ	ded
<dZ
ded<dZd
ed<efd&d�Z
edddddd�											d'd��Zd(d�Zd)d�Zed*d��Zed*d��Z		d+							d,d�Ze						d-d��Ze						d.d��Z						d/d�Zed0d��Zd1d�Zed0d��Zed2d��Zed3d��Ze		d4							d5d ��Zed6d!��Zeej@d"�						d7d#���Z!ee"jFf					d8d$��Z$ee"jFf					d8d%��Z%y)9�GenerativeSelecta&Base class for SELECT statements where additional elements can be
    added.

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

    r��Tuple[ColumnElement[Any], ...]�_order_by_clauses�_group_by_clausesN�Optional[ColumnElement[Any]]�
_limit_clause�_offset_clause�
_fetch_clausezOptional[Dict[str, bool]]�_fetch_clause_optionsr�_for_update_argc��||_yr��r�)r�r�s  r�r�zGenerativeSelect.__init__rs
��(��r�Frc�0�t|||||��|_|S)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 Database, the above would
        render a statement like:

        .. sourcecode:: sql

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

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

        .. sourcecode:: sql

            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
         Database 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,
         for some backends may also be a table expression) which will render
         into a ``FOR UPDATE OF`` clause; supported by PostgreSQL, Oracle
         Database, some MySQL versions and possibly others. May render as a
         table or as a column depending on backend.

        :param skip_locked: boolean, will render ``FOR UPDATE SKIP LOCKED`` on
         Oracle Database 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�r�r�r�rs      r�rz GenerativeSelect.with_for_updateus(��v ,����#�� 
����r�c��|jS)zS
        Retrieve the current label style.

        .. versionadded:: 1.4

        r�r�s r�rEz GenerativeSelect.get_label_style�s��� � � r�c�P�|j|ur|j�}||_|S)a{Return a new selectable with the specified label style.

        There are three "label styles" available,
        :attr:`_sql.SelectLabelStyle.LABEL_STYLE_DISAMBIGUATE_ONLY`,
        :attr:`_sql.SelectLabelStyle.LABEL_STYLE_TABLENAME_PLUS_COL`, and
        :attr:`_sql.SelectLabelStyle.LABEL_STYLE_NONE`.   The default style is
        :attr:`_sql.SelectLabelStyle.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��	_generaterGs  r�rz GenerativeSelect.set_label_style�s,��L���E�)��>�>�#�D� %�D���r�c�^�tjtj|j�S)z9ClauseList access to group_by_clauses for legacy dialects)rH�_construct_rawr�comma_opr�r�s r��_group_by_clausez!GenerativeSelect._group_by_clause��(���(�(����� 6� 6�
�	
r�c�^�tjtj|j�S)z9ClauseList access to order_by_clauses for legacy dialects)rHr�rr�rr�s r��_order_by_clausez!GenerativeSelect._order_by_clause�r�r�c�P�tjtj|||��S)z�Convert 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.

        )r��type_)rrr�LimitOffsetRole)r�r!r�r�s    r��_offset_or_limit_clausez(GenerativeSelect._offset_or_limit_clause�s&������!�!�7��U�
�	
r�c��yr�r��r��clause�attrnames   r��_offset_or_limit_clause_asintz.GenerativeSelect._offset_or_limit_clause_asints��r�c��yr�r�r�s   r�r�z.GenerativeSelect._offset_or_limit_clause_asints��r�c��|�y	|j}tj|�S#t$r}t	j
d|z�|�d}~wwxYw)z�Convert 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)r�rW�asint�AttributeErrorrV�CompileError)r�r�r��value�errs     r�r�z.GenerativeSelect._offset_or_limit_clause_asintsd���>��	%��.�.�E��:�:�e�$�$��
�	��"�"�'�)1�2���
��	�s�&�	A
�A�A
c�:�|j|jd�S)z�Get 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.

        �limit)r�r�r�s r��_limitzGenerativeSelect._limit+s���1�1�$�2D�2D�g�N�Nr�c�"�t|t�S)zkTrue if the clause is a simple integer, False
        if it is not present or is a SQL expression.
        )r�r�)r�r�s  r��_simple_int_clausez#GenerativeSelect._simple_int_clause5s���&�"3�4�4r�c�:�|j|jd�S)z�Get 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.

        �offset)r�r�r�s r��_offsetzGenerativeSelect._offset;s"���1�1�����
�	
r�c�^�|jduxs|jduxs|jduSr�)r�r�r�r�s r��_has_row_limiting_clausez)GenerativeSelect._has_row_limiting_clauseGs=��
���d�*�
.��"�"�$�.�
.��!�!��-�	
r�c�N�dx|_|_|j|�|_|S)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`.

        :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�r�r�r�)r�r�s  r�r�zGenerativeSelect.limitOs,��4;?�>���T�7�!�9�9�%�@����r�c�x�d|_|�dx|_|_|S|j|�|_||d�|_|S)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
        Database, 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��fetchzGenerativeSelect.fetchmsU��Z"����=�>B�B�D���!;���"&�!=�!=�e�!D�D��&�"�*�D�&��r�c�2�|j|�|_|S)a2Return 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.

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

        )r�r�)r�r�s  r�r�zGenerativeSelect.offset�s��,#�:�:�6�B����r�r�c��tjj}dx|_|_|j|j|j||�\|_|_|S)aApply 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)rWr�r�r�r��_make_slicer�r�)r��start�stopr�s    r��slicezGenerativeSelect.slice�s[��Z�>�>�*�*��:>�>���T�7�2:�2F�2F����� 3� 3�U�D�3
�/���D�/��r�c���|s|�	d�_�S|tjur+�xjt�fd�|f|zD��z
c_�S)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�c3�j�K�|]*}tjtj|������,y�w�r&N)rrr�OrderByRole�rRr�r�s  �r�rTz,GenerativeSelect.order_by.<locals>.<genexpr>�:�����,�3�F�� � ��%�%�v�T���3���03)rr7�NO_ARGr��r��_GenerativeSelect__first�clausess`  r��order_byzGenerativeSelect.order_by�s_���H�7�?�%'�D�"����F�M�M�
)��"�"�e�,� '�j�7�2�	,�'�
�"��r�c���|s|�	d�_�S|tjur+�xjt�fd�|f|zD��z
c_�S)apReturn 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�c3�j�K�|]*}tjtj|������,y�wr�)rrr�GroupByRoler�s  �r�rTz,GenerativeSelect.group_by.<locals>.<genexpr>Cr�r�)r�r7r�r�r�s`  r��group_byzGenerativeSelect.group_by!s^���>�7�?�%'�D�"����F�M�M�
)��"�"�e�,� '�j�7�2�	,�'�
�"��r�)r�r�)r�r�r�r�r�rr�r�rr�r�r[r^r_)r�rHr�)r!r`r�r�r�z"Optional[_TypeEngineArgument[int]]r�r�)r�r�r�rr�r)r�zOptional[_OffsetLimitParam]r�rr�r�)r�r�r�rr�zUnion[NoReturn, Optional[int]]r�)r�rGr�r�r�)r�r`r�r[)FF)r�r`r�r�r�r�r�r[)r�r`r�r[)r�rr�rr�r[)r�zMUnion[Literal[None, _NoArg.NO_ARG], _ColumnExpressionOrStrLabelArgument[Any]]r�z(_ColumnExpressionOrStrLabelArgument[Any]r�r[)&r�r�r�r�rrr�r�r�r�r�r�r�r�r4rrErr�r�r�r�rr�r�r�r�r�r�r�r�rWr�r�r7r�r�r�r�r�r�r}r}Zs��
�9;��5�:�8:��5�:�26�M�/�6�37�N�0�7�26�M�/�6�7;��4�;�.2�O�+�2�8K�)����-1�!��A��A��	A�

+�A��
A��A�
�A��A�F!�)�V�
��
��
��
�#�48�	
�!�
��
�2�	
�

�
� ��(��47��	������1��=@��	����%�2�%�>A�%�	'�%�,�O��O�5��	
��	
��
��
�����:� ��	5��5��5��	5�

�5��5�n����0��T���.�/�0��0��0�
�	0�0��0�d�
�M�M�,�
�,�;�
,�
�,��,�\�
�M�M�'�
�'�;�
'�
�'��'r�r}�default�compound_selectc�6�eZdZej		dd��Zy)�CompoundSelectStatec��|jj�}d|_|jD�cic]}|j|��}}|||fScc}wr�)�	statementr�r�rWrg)r��hacky_subqueryrW�ds    r��_label_resolve_dictz'CompoundSelectState._label_resolve_dictNsR�����0�0�2��+0��(�-�/�/�0�/�!�Q�U�U�A�X�/��0��!�Q�w���
1s�AN�r�zbTuple[Dict[str, ColumnElement[Any]], Dict[str, ColumnElement[Any]], Dict[str, ColumnElement[Any]]])r�r�r�rW�memoized_propertyr�r�r�r�r�r�Ls$��	����
���r�r�c�$�eZdZdZdZdZdZdZdZy)�_CompoundSelectKeyword�UNIONz	UNION ALL�EXCEPTz
EXCEPT ALL�	INTERSECTz
INTERSECT ALLN)	r�r�r�r��	UNION_ALLr��
EXCEPT_ALLr��
INTERSECT_ALLr�r�r�r�r�]s ���E��I�
�F��J��I�#�Mr�r�c
���eZdZUdZdZdejfdejfdejfdejfdejfdejfd	ejfd
ejfdejfg	e
jzejzZded
<ded<dZdZ				d#d�Ze				d$d��Ze				d$d��Ze				d$d��Ze				d$d��Ze				d$d��Ze				d$d��Zd%d�Z	d&			d'd�Zd(d�Zd)d�Zd*d�Zdd�											d+d�Zd,�fd �Z e!jDd-d!��Z#e!jD		d.d"��Z$�xZ%S)/�CompoundSelectaXForms 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�rr�r��keywordrRr�zList[SelectBase]TFc���||_|D�cgc]8}tjtj||��j|����:c}|_tj|�ycc}w)Nr&r�)	r�rrr�CompoundElementRoleryr�r}r�)r�r�r��ss    r�r�zCompoundSelect.__init__�sn��
���
�	
���
����)�)�1�D�
��j��j�&�
'��	
���	�!�!�$�'��
s�=A'c�6�ttjg|���Sr�)r�r�r��r�r�s  r��
_create_unionzCompoundSelect._create_union�s���4�:�:�E�W�E�Er�c�6�ttjg|���Sr�)r�r�r�r�s  r��_create_union_allz CompoundSelect._create_union_all�����4�>�>�I��I�Ir�c�6�ttjg|���Sr�)r�r�r�r�s  r��_create_exceptzCompoundSelect._create_except�s���4�;�;�F�g�F�Fr�c�6�ttjg|���Sr�)r�r�r�r�s  r��_create_except_allz!CompoundSelect._create_except_all�s���4�?�?�J�'�J�Jr�c�6�ttjg|���Sr�)r�r�r�r�s  r��_create_intersectz CompoundSelect._create_intersect�r�r�c�6�ttjg|���Sr�)r�r�r�r�s  r��_create_intersect_allz$CompoundSelect._create_intersect_all�s���4�B�B�M�W�M�Mr�c�<�|jdj�S�Nr)r�rMr�s r�rMzCompoundSelect._scalar_type�s���|�|�A��+�+�-�-r�Nc��t|�Sr�)rfrws  r�ryzCompoundSelect.self_group�s��'�t�,�,r�c�L�|jD]}|j|�s�yy�NTF)r�r�)r�r�r�s   r�r�zCompoundSelect.is_derived_from�s&�����A�� � ��,���r�c��|j|urF|j�}|jdj|�}|g|jddz|_|S�Nrr)r�r�r�r)r�rH�select_0s   r�rzCompoundSelect.set_label_style�sR�����E�)��>�>�#�D��|�|�A��6�6�u�=�H�$�:����Q�R�(8�8�D�L��r�c��|jdj�}||jdur(|j�}|g|jddz|_|Sr�)r�rXr�)r��
new_selects  r�rXz*CompoundSelect._ensure_disambiguated_names�sR���\�\�!�_�@�@�B�
��T�\�\�!�_�,��>�>�#�D�&�<�$�,�,�q�r�*:�:�D�L��r�r;c
���|jd}|jtur|j|j�}t	t|j�D��cgc]\}}d|dzi|f��c}}D�	��
cgc]9\}	}|jD�
cgc]}
t|
�r|
j|	��� c}
��;c}
}}	�}|j|||||��ycc}}wcc}
wcc}
}}	w)Nr�weightrrt)
r�r�r�r�zip�	enumerater�r%�	_annotater�)r�r�r�r�r�r<r��i�stmt�ddrW�extra_col_iterators            r�r�z2CompoundSelect._generate_fromclause_column_proxies�s��� �<�<��?�����$7�7��/�/��0A�0A�B�H�!�$-�T�\�\�#:�!�#:���4���A��&��-�#:�!�
�!�H�B��"�7�7��7��(��+��K�K��O�7��
!�
�
��&	�4�4���#5�#�%�	5�	
��!����
s�C
�5C�#C�.C�Cc�h��t�|�|�|jD]}|j|��yr�)r�r�r�)r�r�r.rJs   �r�r�z&CompoundSelect._refresh_for_new_columns,���
��'��/��l�l�F��*�*�6�2�#r�c�4�|jdjSr�)r�r�r�s r�r�z$CompoundSelect._all_selected_columnss���|�|�A��4�4�4r�c�4�|jdjS)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:r�s r�r:zCompoundSelect.selected_columns!s��,�|�|�A��/�/�/r�)r�r�r��(_SelectStatementForCompoundArgument[_TP])r�rr��CompoundSelect[_TP]r`r�)rxr�r�rLr�r_rar\r�r�r[)&r�r�r�r�r�rSr�r�
dp_plain_dictr�r+rzrpr�r�rr=�_auto_correlater�rr�r�r�r�r�r�rMryr�rrXr�r�rWr�r�r:rrs@r�r�r�fs�����('�N��)�?�?�@�
�/�@�@�A�
�0�A�A�B�
�/�@�@�A�
$�&7�&E�&E�F�
 �"3�"I�"I�J�
 �"3�"I�"I�J�
� 1� B� B�C�
�)�3�3�4�
	
�#�
H�
H�	I��
-�
-�	.��/�� �����O�
(�'�
(�;�
(��F�?�F�	�F��F�
�J�?�J�	�J��J�
�G�?�G�	�G��G�
�K�?�K�	�K��K�
�J�?�J�	�J��J�
�N�?�N�	�N��N�
.�15�-�-�-�	�-�
���"
�3
��3
�@�3
��	3
�
3�3
�!
�3
�
�3
�j3�

�"�"�5�#�5�
�"�"�0�	2�0�#�0r�r�r.c��eZdZUdZerded<nGd�de�Zer
e				dd��Z							dd�Z
edd��Ze				dd��Ze						dd	��Z
e				dd
��Ze				dd��Zdd�Ze		d							dd��Z		d					d d�Z		d!d�Ze				d"d��Zed#d��Z						d$d�Zej0d�										d%d��Zej0d�				d&d��Zy
)'r�)�from_clauses�froms�columns_plus_namesr�r9�default_select_compile_optionsc��eZdZgZy)�*SelectState.default_select_compile_optionsN)r�r�r��_cache_key_traversalr�r�r�rrLs��#%� r�c��yr�r��r�r�s  r��get_plugin_classzSelectState.get_plugin_classQ���!$r�c�^�||_|j|_|jD](}|j	|j|j
��*|jr&|j	|j|j
�|j
|�|_|jd�|_	yr8)
r��	_from_objr
�_memoized_select_entities�_setup_joins�_raw_columns�
_get_fromsrr�r)r�r��compilerr��memoized_entitiess     r�r�zSelectState.__init__Vs���#���%�/�/���!*�!D�!D�����!�.�.�0A�0N�0N�
�"E�
�!�!����i�4�4�i�6L�6L�M��_�_�Y�/��
�"+�"H�"H��"N��r�c��td��)NzLThe default SELECT construct without plugins does not implement this method.r�)r�s r��_plugin_not_implementedz#SelectState._plugin_not_implementedks��!�
%�
�	
r�c
�~�|jd�D���cgc]\}}}}}||j|d���c}}}Scc}}}w)NF)r�r�expr)r�r)r�r�rr�r!s     r��get_column_descriptionsz#SelectState.get_column_descriptionsrsT���6�6�u�=�	
�>�'��4��G�Q�	�����
�>�	
�		
��	
s�8c�$�|j�yr�)r!)r�r��from_statements   r�r&zSelectState.from_statement�s��	�#�#�%r�c��|jtjjd�|jD���S)Nc3�4K�|]}|j���y�wr�r2)rRr!s  r�rTz7SelectState.get_columns_clause_froms.<locals>.<genexpr>�s����*�5K�'��%�%�5K�s�)�_normalize_fromsr�r��
from_iterablerrs  r��get_columns_clause_fromsz$SelectState.get_columns_clause_froms�s<���#�#��O�O�)�)�*�5>�5K�5K�*�
�
�	
r�c�v�����|tu�|tu�t��t��	d					d����fd�
}|S)Nc�j��t|�rytr
t|�sJ��s|j}|�d}|S�r|jn|j}|�-d}|�vr|j|��zS�j
|�|S|�vr �r|j�zS|j�zS�j
|�|S)N�	_no_label)	r)rr%�
_proxy_keyr��_anon_labelr��_anon_tq_key_label�_anon_key_label)rW�col_namer�r�r��par�s   ����r��goz1SelectState._column_naming_convention.<locals>.go�s�����a� ���(��+�+�+���|�|���<�&�D���&5�1�?�?�1�<�<�D��|�"���5�=��=�=��.��3�3��I�I�d�O��K����'��(�(�2�-���*�*�R�/���	�	�$���r�r�)rWr�r3r�r�r�)r�r�rTr`)r�rmr5r�r�r4r�s   @@@@r�r�z%SelectState._column_naming_convention�s[���&�)G�G���$4�4��
�
�����'+�!	�4�!	�#�!	��!	�!	�F�	r�c��ix|_}|jtj|jtjj|jD�cgc]}|j��c}�tjj|jD�cgc]}|j��c}��||��Scc}wcc}w)N)�check_statement�ambiguous_table_name_map)	�_ambiguous_table_name_mapr)r�r�r
r*rr3�_where_criteria)r�r�r8r!s    r�rzSelectState._get_froms�s���DF�F��&�)A��$�$��O�O��!�!����-�-�(1�'=�'=��'=�G� �-�-�'=������-�-�(1�'@�'@��'@�G� �-�-�'@���
�&�%=�#%�
�	
����s�B;�CNc
�(��t�}g}|D]x}t|�r#|j|urtjd��|j|j�r�M|j|�|j|j��z|r{ttjj|D�cgc]}t|j���c}��}|r|D�cgc]	}||vs�|��}}���j�fd�|D��|Scc}wcc}w)a0given 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.

        z-select() construct refers to itself as a FROMc3��K�|]y}|jD]h}t|�r[|jrO|j�vrA|jt	j
t
|j�|j�f���j�{y�wr�)r3r(r*r�rDr+r�)rR�item�frr8s   �r�rTz/SelectState._normalize_froms.<locals>.<genexpr>su�����0�!&��"�0�0����|��	�	����'?�?����(�7�7� ����M�2�7�7���1��!&�s�A?B)r`r'r!rV�InvalidRequestErrorrDrBr�r�r�r�r*r1r')	r��iterable_of_fromsr7r8�seenrr=r��toremoves	   `     r�r)zSelectState._normalize_froms�s���!$���"$��%�D��4� �T�\�\�_�%D��-�-�C����$�$�T�%5�%5�6����T�"����D�,�,�-�&������-�-�<A�B�E�q�^�A�M�M�2�E�B���H�
�%*�?�E�q�Q�h�->��E��?�'�3�(�/�/�0�!&�0�����/C��@s�/D
�	D�&Dc�x�|j}|jjrC|jj}|r+|D�cgc] }|tt||xsd�|�vr|��"}}|jj�?|D�cgc]4}|tt||xsd�|jj�vr|��6}}|jjrZ|rXt|�dkDrJ|D�cgc]}|t||�vr|��}}t|�s"tjd|jz��|Scc}wcc}wcc}w)aReturn 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�rz�Select statement '%r' returned no FROM clauses due to auto-correlation; specify correlate(<tables>) to control correlation manually.)
rr��
_correlater.�_correlate_exceptr-rr�rVr?)r��explicit_correlate_froms�implicit_correlate_fromsr�to_correlater�s      r��_get_display_fromszSelectState._get_display_fromssu���
�
���>�>�$�$��>�>�4�4�L��#�
�"���/�,�!�#;�#A�r��%�	���"��
��>�>�+�+�7��
��A��)�(��7�=�2���N�N�4�4�	����
�
�
�N�N�*�*�(��E�
�Q�����A��+�E�3K�L�M���
���u�:��-�-� �
#'�.�.�1������_
��
��"s�%D-�9D2�%D7c��|jjD�cic])}|jr|jxs|j|��+}}t|j�D�cic]}|jr
|j|��}}|j�}|j�D]\}}|j||��|||fScc}wcc}wr�)
r�r��_allow_label_resolver�rgr8r�copy�items�
setdefault)r�rW�	with_cols�
only_froms�	only_colsrgr�s       r��"_memoized_attr__label_resolve_dictz.SelectState._memoized_attr__label_resolve_dictUs����^�^�9�9�4
�9���%�%�
�K�K� �1�5�5�!�#�9�	�4
�'�t�z�z�2�5
�2���%�%�
�E�E�1�H�2�	�5
�
4=�>�>�3C�	�$�*�*�,�J�C��� � ��e�,�-��*�i�/�/��4
��
5
s�.C�  Cc�@�|jr|jddSy)N���r)r)r�rs  r��determine_last_joined_entityz(SelectState.determine_last_joined_entityls&������$�$�R�(��+�+�r�c�R�t|j�D�cgc]}|��c}Scc}wr�)r8r)r�r�rWs   r��all_selected_columnsz SelectState.all_selected_columnsus'��,�Y�-C�-C�D�E�D�a��D�E�E��Es�	$c	��|D]�\}}}}tr|�t|t�sJ�|d}|d}|�|j||||�\}}	n|j	|�}	tr&t|t
�sJ�|�t|t�sJ�|	�I|j|	}
|jd|	t|
||||��fz|j|	dzdz|_��|�J�|jt|||||��fz|_��y)Nr4r5rr)rr�rJ�"_join_determine_implicit_left_side�_join_place_explicit_left_sider�r
r1)r��args�raw_columnsr2r3r��flagsr4r5�replace_from_obj_index�left_clauses           r�rzSelectState._setup_joinsysY��
-1�(�E�8�T�5���'�%�h�
�>�>�>��I�&�G���=�D��|��;�;���u�h����*�
,0�+N�+N��,�'��!�%��4�4�4��'�%�h�
�>�>�>�%�1�#�/�/�0F�G���%�%�&=�'=�>��'�!�$�$+�!%���	��'�'�(>��(B�(D�E�
F��!��'�'�'�$(�$5�$5���u�h��d�K�9�%��!�e-1r�r�c	��tjj}d}|j}|r,|j	|||�}t|�dk(r�|d}||}n�i}	|j}
tjtjj|D�cgc]}|j��c}�tjj|
jD�cgc]}|j��c}��D]}d|	|<�	t|	j��}
|j	|
||�}t|�dk(r|
|d}t|�dkDrtjd��|stjd|�d���||fScc}wcc}w)z�When 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.

        Nrrr�aCan'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.zDon'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.)rWr�r�r
�find_left_clause_to_join_fromr�r�r�r�r*r3r:r��keysrVr?)r�r\r�r2r3r�r^r
�indexes�	potentialr�r!�from_clause�all_clausess              r�rYz.SelectState._join_determine_implicit_left_side�s����>�>�*�*��04���(�(���!)�!G�!G��e�X�"�G��7�|�q� �)0���&�#�$:�;���I����I�(������-�-�:E�F�+�w�W�*�*�+�F�����-�-�(1�'@�'@��'@�G� �-�-�'@���	
 ��*,�	�+�&�
 ��y�~�~�/�0�K��<�<��U�H��G��7�|�q� �"�7�1�:�.���w�<�!���)�)�.��
���)�)�
27�	9��
��+�+�+��IG��s�E=�Fc��d}tjj}t|jj��}|r|j
|j|�}ng}t|�dkDrtjd��|r|d}|S)NrzrCan't identify which entity in which to assign the left side of this join.   Please use a more specific ON clause.r)rWr�r�r�r��_iterate_from_elements�#find_left_clause_that_matches_givenr
r�rVr?)r�r�r^r�r
rcs      r�rZz*SelectState._join_place_explicit_left_side�s���15���>�>�*�*���D�N�N�A�A�C�D���!)�!M�!M��!�!�4�"�G��G��w�<�!���)�)���
��%,�Q�Z�"�
&�%r�)r�r>r��Type[SelectState])r�r}rrtr�r�r�r)r�r}r�zList[Dict[str, Any]])r�r}r&�roles.ReturnsRowsRoler�r�)r�r}r�r�)rmr�r��_LabelConventionCallabler�)r@r{r7zOptional[Select[Any]]r8z Optional[_AmbiguousTableNameMap]r�r�)rF�Optional[Sequence[FromClause]]rGrnr�r�r�)rr}r�zOptional[_JoinTargetElement])r�r}r�r�)r[�Tuple[_SetupJoinsElement, ...]r\�List[_ColumnsClauseElement]r�r�)
r\rpr�r�r2�_JoinTargetElementr3r�r�z*Tuple[Optional[FromClause], Optional[int]])r�r�r�r�)r�r�r��	__slots__rrr9rrrr�r!r$r&r+r�rr)rIrRrUrWrrWr�rYrZr�r�r�r�r�?s����I��(8�8�	&�-=�	&��	�	$�&�	$�
�	$�
�	$�O��O��O��	O�*�
��
��
�#�
�	�
��
��&�#�&�5J�&�	�&��&�
�
�#�
�	�
��
��-�*�-�	!�-��-�^
�0�26�EI�	5�/�5�/�5�#C�	5�

�5��5�rDH�CG�B�"@�B�#A�B�
�	B�H0�
�0�.����	%�����F��F�9�,�9�1�9�
�	9�v�T���.�/�E,�0�E,�#�E,�"�	E,�
/�E,�
4�
E,�0�E,�N�T���.�/�&��&�	�&�0�&r�r�c�8�eZdZUdZded<ded<ded<d
d�Zy	)�_SelectFromElementsr�rprr~r:�Tuple[FromClause, ...]rc#�fK�t�}|jD]-}|jD]}||vr�|j|�|����/|jD]-}|jD]}||vr�|j|�|����/|j
D]}||vr�|j|�|���y�wr�)r`rr3r�r:r)r�rAr!r>s    r�rhz*_SelectFromElements._iterate_from_elements&s������u���(�(�G��+�+����:���������	,�)��+�+�G��+�+����:���������	,�,��~�~�G��$����H�H�W���M�	&�s�B/B1N)r�zIterator[FromClause])r�r�r�rrrrhr�r�r�rtrts���I�-�-�3�3�%�%�r�rtc���eZdZUdZdZdejfdejfdejfgZ	de
d<de
d	<d
e
d<de
d<de
d<ejZ
dd
�Zedd��Zy)�_MemoizedSelectEntitiesarepresents partial state from a Select object, for the case
    where Select.columns() has redefined the set of columns/entities the
    statement will be SELECTing from.  This object represents
    the entities from the SELECT before that transformation was applied,
    so that transformations that were made in terms of the SELECT at that
    time, such as join() as well as options(), can access the correct context.

    In previous SQLAlchemy versions, this wasn't needed because these
    constructs calculated everything up front, like when you called join()
    or options(), it did everything to figure out how that would translate
    into specific SQL constructs that would be ready to send directly to the
    SQL compiler when needed.  But as of
    1.4, all of that stuff is done in the compilation phase, during the
    "compile state" portion of the process, so that the work can all be
    cached.  So it needs to be able to resolve joins/options2 based on what
    the list of entities was when those methods were called.


    �memoized_select_entitiesrr�
_with_optionsrRr�zOptional[ClauseElement]r(rprozTuple[ExecutableOption, ...]c��|jj|j�}|jj�D��cic]\}}||��
c}}|_|jj	d|�|_|Scc}}w)Nr()rJr#r\rM�getr()r�r�rW�k�vs     r�r,z_MemoizedSelectEntities._clonedsi���N�N�"�"�4�>�>�2��'+�}�}�':�':�'<�=�'<�t�q�!�a��d�'<�=��
����*�*�>�4�@������>s�
A<c��|js|jrit�}|j|_|j|_|j|_|xj|fz
c_g|_dx|_|_yyr&)rrzrxrr)r��select_stmtr�s   r��_generate_for_statementz/_MemoizedSelectEntities._generate_for_statementksv���#�#�{�'@�'@�*�,�D� +� 8� 8�D�� +� 8� 8�D��!,�!:�!:�D���1�1�d�W�<�1�')�K�$�CE�E�K�$�{�'@�(Ar�N)r�rr�r[)r�r}r�r�)r�r�r�r�r�rSr��dp_setup_join_tuple�dp_executable_optionsr�rrW�
EMPTY_DICT�_annotationsr,rr�r�r�r�rxrx>s����(0�N�
�*�@�@�A�	�*�>�>�?�	�+�A�A�B�3��/��*�)�-�-�0�0�/�/��?�?�L���	F��	Fr�rxc�6	��eZdZUdZdZdZded<dZded<ded	<d
Zded<dZ	d
ed<dZ
ded<dZded<dZd
ed<dZ
d
ed<dZded<dZdZej$Zded<d	ej*fdej,fdej*fdej.fdej.fdej.fdej.fdej0fdej.fdej.fdej2fdej2fdej2fdej4fd ej2fdej6fdej.fd!ej8fgej<zej@ze!jDze#jHze%jLze'jPzZ)d"ed#<e)dejTfgzZ+d$ed%<d&ed'<e,djd(��Z-dkd)�Z.dld*�Z/dmd+�Z0		dnd,�Z1e2r'e3				dod-��Z4e3				dpd.��Z4e3dqd/��Z4dqd0�Z4drd1�Z5e6dsd2��Z7				dtd3�Z8e9	dud
d
d4�									dvd5��Z:	dud
d6�									dwd7�Z;e9	dud
d
d4�											dxd8��Z<	dud
d6�							dyd9�Z=dzd:�Z>e6e?j�d;d<�dzd=���ZAe6d{d>��ZBe6d|d?��ZCd}d@�ZDeEf					d~�fdA�
ZFd�fdB�ZGe9				d�dC��ZH				d�dD�ZIe?j�dEdF�d�dG��ZJe?j�dH�d�d�dI��ZLe3dJdK�					d�dL��ZMe3dJdK�							d�dM��ZMe3dJdK�									d�dN��ZMe3dJdK�											d�dO��ZMe3dJdK�													d�dP��ZMe3dJdK�															d�dQ��ZMe3dJdK�																	d�dR��ZMe3dJdK�																			d�dS��ZMe3d
dK�							d�dT��ZMe9d
dK�							d�dU��ZMe6d�dV��ZNeNZOe9d�dW��ZPe9d�dX��ZQe9d�dY��ZRe9d�dZ��ZSe9				d�d[��ZTe9				d�d\��ZUeV		d�d]��ZWeVd|d^��ZXd�d_�ZYdd`�											d�da�ZZd�db�Z[	du			d�dc�Z\				d�dd�Z]				d�de�Z^				d�df�Z_				d�dg�Z`				d�dh�Za				d�di�Zb�xZcS)�r-aRepresents 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�rorzTuple[TODO_Any, ...]rrprFr��	_distinctr~�_distinct_onrurDNz Optional[Tuple[FromClause, ...]]rEr:�_having_criteriarTr9�_compile_optionsrr�r�r�r�r�r�r�rRr�rsrrj�_compile_state_factoryc�n�tjt�}|jj|�|S)z�Create a :class:`.Select` using raw ``__new__`` with no coercions.

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

        )r-r#r\r�)r�r�rs   r��_create_raw_selectzSelect._create_raw_select�s)���~�~�f�%���
�
���R� ��r�c��|D�cgc](}tjtj||����*c}|_t
j
|�ycc}w)z�Construct a new :class:`_expression.Select`.

        The public constructor for :class:`_expression.Select` is the
        :func:`_sql.select` function.

        r&N)rrrrrr}r��r��entities�ents   r�r�zSelect.__init__�sU�� �	
� ��
����'�'��D�
� �	
���	�!�!�$�'��
s�-Ac��|jstS|jd}t|j�}|djSr�)rrQr�rlr)r�rr�s   r�rMzSelect._scalar_type�s>��� � ��O�� � ��#���D�)�)�*���A�w�|�|�r�c� �|j|�S)z3A synonym for the :meth:`_sql.Select.where` method.��where)r��criterias  r��filterz
Select.filter�s���t�z�z�8�$�$r�c���|jr+tj|�j}||�}|�|S|jr|jdS|j
dSr�)rr�rrUrr)r��meth�_last_joined_entitys   r��_filter_by_zerozSelect._filter_by_zero�sh��
����/�/���*�*�
�#'�t�*��"�.�*�*��>�>��>�>�!�$�$�� � ��#�#r�c��yr�r�r�s r�r�zSelect.scalar_subqueryrr�c��yr�r�r�s r�r�zSelect.scalar_subquery
s��),r�c��yr�r�r�s r�r�zSelect.scalar_subquerys��8;r�c��yr�r�r�s r�r�zSelect.scalar_subquerys��r�c��|j�}|j�D��cgc]\}}t||�|k(��}}}|j|�Scc}}w)zWapply the given filtering criterion as a WHERE clause
        to this select.

        )r�rMr/r�)r��kwargs�from_entityrgr�r�s      r��	filter_byzSelect.filter_bysb��
�*�*�,��%�l�l�n�
�,�
��U�
"�+�s�3�u�<�,�	�
��t�{�{�G�$�$��	
s�Ac�P�tj|�j}||�S)a5Return 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

        )r�rr$�r�r�s  r��column_descriptionszSelect.column_descriptions!s%��R�+�+�D�1�I�I���D�z�r�c�R�tj|�j}|||�S)a�Apply the columns which this :class:`.Select` would select
        onto another statement.

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


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

        .. seealso::

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

        )r�rr&)r�r�r�s   r�r&zSelect.from_statementMs'��,�+�+�D�1�@�@���D�)�$�$r�rc���tjtj||��}|�%tjtj|�}nd}|xj
||d||d�ffz
c_|S)a�	Create a SQL JOIN against this :class:`_expression.Select`
        object's criterion
        and apply generatively, returning the newly resulting
        :class:`_expression.Select`.

        E.g.::

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

        The above statement generates SQL similar to:

        .. sourcecode:: sql

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

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

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

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


        :param target: target table to join towards

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

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

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

        .. seealso::

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

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

            :meth:`_expression.Select.join_from`

            :meth:`_expression.Select.outerjoin`

        r&Nr)rrr�JoinTargetRoler�r)r��targetr3r4r5�join_target�onclause_elements       r�r6zSelect.joinfs|��P �&�&�� � �&��
����(�/�/��0B�0B�H�M��#������ ��#�T�2�	
�
�	
���r�)r5c�.�|j|||d|��S)aCreate 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�r3r4r5)�	join_from)r��from_r�r3r5s     r��outerjoin_fromzSelect.outerjoin_from�s%���~�~��6�H�d���
�	
r�c�*�tjtj||��}tjtj||��}|�%tjtj
|�}nd}|xj|||||d�ffz
c_|S)aCreate 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:

        .. sourcecode:: sql

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

        .. versionadded:: 1.4

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

        :param target: target table to join towards

        :param onclause: ON clause of the join.

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

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

        .. seealso::

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

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

            :meth:`_expression.Select.join`

        r&Nr)rrrr r�r�r)r�r�r�r3r4r5r�r�s        r�r�zSelect.join_from�s���r� � �� � �%�t�
�� �&�&�� � �&��
����(�/�/��0B�0B�H�M��#������ ��#�T�2�	
�
�	
���r�c�,�|j||d|��S)a�Create a left outer join.

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

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

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

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

        .. seealso::

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

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

            :meth:`_expression.Select.join`

        Tr�)r6)r�r�r3r5s    r�r8zSelect.outerjoin!s��R�y�y��(�D�t�y�L�Lr�c�b�|j�}|j||�j�S)aGCompute 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`

        )�_default_compilerr�rI)r�rs  r��get_final_fromszSelect.get_final_fromsLs/��J�)�)�+���*�*�4��:�M�M�O�Or�z1.4.23zqThe :attr:`_expression.Select.froms` attribute is moved to the :meth:`_expression.Select.get_final_froms` method.c�"�|j�S)zYReturn the displayed list of :class:`_expression.FromClause`
        elements.


        )r�r�s r�rzSelect.fromsus���#�#�%�%r�c�J�tj|�j|�S)a�Return the set of :class:`_expression.FromClause` objects implied
        by the columns clause of this SELECT statement.

        .. versionadded:: 1.4.23

        .. seealso::

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

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

        )r�rr+r�s r��columns_clause_fromszSelect.columns_clause_froms�s%��"�+�+�D�1�J�J��
�	
r�c�,�t|j�S)a0An 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.

        )�iterr�r�s r��
inner_columnszSelect.inner_columns�s���D�.�.�/�/r�c�v�|�||jvry|j�D]}|j|�s�yyr�)rBrhr�)r�r�r�s   r�r�zSelect.is_derived_from�sA���!�d�j�.D�.D�&D���,�,�.�A�� � ��,��/�r�c
���	�ttjt|j�t|j
�t|jD�cgc]}|d��	c}���}|D�cic]}|||fi|����c}�	|jD�cgc]}||fi|����
}}�	j�D�chc]}t|t�s�|��c}j|�j|�}t|�t|�z|_						d�	fd�}||d<t�
|�8d|dd�|��|j�ycc}wcc}wcc}wcc}w)Nrc���t|t�r.|j�vr �|jj|�}|Syr�r�r�s   �r�r�z'Select._copy_internals.<locals>.replace�r�r�r�)r)r��
omit_attrsr�r�)r`r�r�r3rr:rrr�r�r1�
differencer�r�r�r�)r�r�r�rr�r��existing_from_obj�	add_fromsr�r�rJs         @�r�r�zSelect._copy_internals�s]�����O�O��t�0�0�1��t�3�3�4��D�4E�4E�F�4E�D��Q��4E�F�G�
�
�
�1>�>�
�1�Q��a��2��&�
�>�	�6:�^�^�D�^��U�1�^��^�^��D�!�(�(�*�B�*�1�j��D�.A�Q�*�B�
�Z�
�
&�
�Z�)�
*�	��0�1�E�)�4D�D���	�@�	��	�/�	� ��9�
�	���M�e��M�"�M�� � �"��S G��?��E��Bs�D9�(D>�
E�.E�Ec�j��tjt�|�dddi|��|j	��S)Nr�)rrDrEr�)r�r�r��get_childrenrh)r�r�rJs  �r�r�zSelect.get_children�s?�������G� �
�K�
��
�
�'�'�)�
�	
r�c	��|j�|j|D�cgc](}tjtj
||����*c}z|_|Scc}w)a�Return a new :func:`_expression.select` construct with
        the given entities appended to its columns clause.

        E.g.::

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

        The original expressions in the columns clause remain in place.
        To replace the original expressions with new ones, see the method
        :meth:`_expression.Select.with_only_columns`.

        :param \*entities: column, table, or other entity expressions to be
         added to the columns clause

        .. seealso::

            :meth:`_expression.Select.with_only_columns` - replaces existing
            expressions rather than appending.

            :ref:`orm_queryguide_select_multiple_entities` - ORM-centric
            example

        r&)r�rrrrr)r�r�r�s   r��add_columnszSelect.add_columns�sh��6	
� � �"� �-�-�#�	1
�#��
����'�'��t�
�#�	1
�
������
1
s�-Ac��tj|�D�cgc](}tjtj
||����*c}|_ycc}w)Nr&)rWr
rrrrrr�s   r��
_set_entitieszSelect._set_entitiessN���|�|�H�-�	
�.��
����'�'��D�
�.�	
����
s�-Ar�z�The :meth:`_expression.Select.column` method is deprecated and will be removed in a future release.  Please use :meth:`_expression.Select.add_columns`c�$�|j|�S)a�Return a new :func:`_expression.select` construct with
        the given column expression added to its columns clause.

        E.g.::

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

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

        )r�r�s  r�r�z
Select.column s��(����'�'r�r�c��|jtjjj|j
g|j|jz��d|i��}|S)a"Return a new :func:`_expression.select` construct with redundantly
        named, equivalently-valued columns removed from the columns clause.

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

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

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

        �
only_synonyms)�with_only_columnsrWr�r�r�r�r:r)r�r��wocs   r�r�zSelect.reduce_columns6s_��2%�d�$�$�
�^�^�
$�
$�
3�
3��*�*���&�&����7��+��
���
r�.)�maintain_column_fromsc��yr�r�)r��
_Select__ent0r�s   r�r�zSelect.with_only_columns]s��!r�c��yr�r�)r�r��
_Select__ent1r�s    r�r�zSelect.with_only_columnsbs��#&r�c��yr�r�)r�r�r��
_Select__ent2r�s     r�r�zSelect.with_only_columnsks��(+r�c��yr�r�)r�r�r�r��
_Select__ent3r�s      r�r�zSelect.with_only_columnsus��-0r�c��yr�r�)r�r�r�r�r��
_Select__ent4r�s       r�r�zSelect.with_only_columns�s��25r�c��yr�r�)r�r�r�r�r�r��
_Select__ent5r�s        r�r�zSelect.with_only_columns�s��7:r�c��yr�r�)	r�r�r�r�r�r�r��
_Select__ent6r�s	         r�r�zSelect.with_only_columns�s��<?r�c	��yr�r�)
r�r�r�r�r�r�r�r��
_Select__ent7r�s
          r�r�zSelect.with_only_columns�s	��ADr�c��yr�r�)r�r�r��_Select__kws    r�r�zSelect.with_only_columns�s��r�c�\�|r
t��|j�|r'|jj|g|j���t
j
|�tjdd|�D�cgc]&}tjtj|���(c}|_|Scc}w)a�Return a new :func:`_expression.select` construct with its columns
        clause replaced with the given entities.

        By default, this method is exactly equivalent to as if the original
        :func:`_expression.select` had been called with the given entities.
        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 \*entities: column expressions to be used.

        :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

        r�zSelect.with_only_columns)
r"�_assert_no_memoizationsr�non_generativer�rxr�r�!_expression_collection_was_a_listrrrr)r�r�r�r�rWs     r�r�zSelect.with_only_columns�s���p��(�N�
	
�$�$�&� �+�D���+�+��
��0�0�
�
	 �7�7��=��@�@��6���
���
���U�4�4�a�8��
������

s�4+B)c�@�tj|j�S)aReturn the completed WHERE clause for this
        :class:`_expression.Select` statement.

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


        .. versionadded:: 1.4

        )rF�_construct_for_whereclauser:r�s r��whereclausezSelect.whereclauses ��!�;�;�� � �
�	
r�c���t|jt�sJ�|D]>}tjt
j||��}|xj|fz
c_�@|S)z�Return a new :func:`_expression.select` construct with
        the given expression added to
        its WHERE clause, joined to the existing clause via AND, if any.

        r&)r�r:r�rrr�WhereHavingRole)r�r��	criterion�where_criterias    r�r�zSelect.where#s^���$�.�.��6�6�6�$�I�1:�1A�1A��%�%�y��2�N�
� � �^�$5�5� �	%�
�r�c��|D]>}tjtj||��}|xj|fz
c_�@|S)z�Return a new :func:`_expression.select` construct with
        the given expression added to
        its HAVING clause, joined to the existing clause via AND, if any.

        r&)rrrr�r�)r��havingr��having_criterias    r�r�z
Select.having4sH�� �I�'�.�.��%�%�y���O�
�!�!�o�%7�7�!�	 �
�r�c�x��|r/d�_�jt�fd�|D��z�_�Sd�_�S)a.Return a new :func:`_expression.select` construct which
        will apply DISTINCT to the SELECT statement overall.

        E.g.::

            from sqlalchemy import select

            stmt = select(users_table.c.id, users_table.c.name).distinct()

        The above would produce an statement resembling:

        .. sourcecode:: sql

            SELECT DISTINCT user.id, user.name FROM user

        The method also accepts an ``*expr`` parameter which produces the
        PostgreSQL dialect-specific ``DISTINCT ON`` expression.  Using this
        parameter on other backends which don't support this syntax will
        raise an error.

        :param \*expr: optional column expressions.  When present,
         the PostgreSQL dialect will render a ``DISTINCT ON (<expressions>)``
         construct.  A deprecation warning and/or :class:`_exc.CompileError`
         will be raised on other backends.

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

        Tc3�j�K�|]*}tjtj|������,y�wr�)rrr�ByOfRole)rR�er�s  �r�rTz"Select.distinct.<locals>.<genexpr>ds/�����:��A�� � �����$�O�O��r�)r�r�r�)r�r#s` r��distinctzSelect.distinctCsK���>�!�D�N� $� 1� 1�E�:��:�5�!�D����"�D�N��r�c�V���xjt�fd�|D��z
c_�S)aReturn 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)

        c3�j�K�|]*}tjtj|������,y�wr��rrrr )rRr�r�s  �r�rTz%Select.select_from.<locals>.<genexpr>�s:����� 
�$�
�
����$�$�j��
�
�$�r�)rr�)r�rs` r�rzSelect.select_fromls1���F	
���%� 
�$�	 
�
�	
���r�c���d|_|r|ddvr,t|�dkDrtjd��d|_|S|jtd�|D��z|_|S)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: one or more :class:`.FromClause` or other
         FROM-compatible construct such as an ORM mapped entity to become part
         of the correlate collection; alternatively pass a single value
         ``None`` to remove all existing correlations.

        .. seealso::

            :meth:`_expression.Select.correlate_except`

            :ref:`tutorial_scalar_subquery`

        Fr�FNrzKadditional FROM objects not accepted when passing None/False to correlate()r�c3�dK�|](}tjtj|����*y�wr�r��rRr�s  r�rTz#Select.correlate.<locals>.<genexpr>�s'����6�CN�a�	� � ��!5�!5�q�9�;���.0)rr�rVr�rDr��r��fromclausess  r�rzSelect.correlate�s}��v %����k�!�n�
�=��;��!�#��'�'�8���!�D�O�
��#�o�o��6�CN�6�1��D�O��r�c���d|_|r|ddvr,t|�dkDrtjd��d|_|S|jxsdtd�|D��z|_|S)a�Return a new :class:`_expression.Select`
        which will omit the given FROM
        clauses from the auto-correlation process.

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

        If ``None`` is passed, or no arguments are 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`

        Frr�rzRadditional FROM objects not accepted when passing None/False to correlate_except()r�c3�dK�|](}tjtj|����*y�wr�r�r�s  r�rTz*Select.correlate_except.<locals>.<genexpr>
s(����L�CN�a�	� � ��!5�!5�q�9�;�r�)rr�rVr�rEr�r�s  r��correlate_exceptzSelect.correlate_except�s���B %����k�!�n�
�=��;��!�#��'�'�?���&(�D�"���	'+�&<�&<�&B��e�L�CN�L�G�&�D�"��r�c���tdtj|j��}t	|j
D�cgc]}t
|�r
||�|f��c}�}|j�Scc}w)a�A :class:`_expression.ColumnCollection`
        representing the columns that
        this SELECT statement or similar construct returns in its result set,
        not including :class:`_sql.TextClause` constructs.

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

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

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

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

        A use case for the :attr:`_sql.Select.selected_columns` collection is
        to allow the existing columns to be referenced when adding additional
        criteria, e.g.::

            def filter_on_id(my_select, id):
                return my_select.where(my_select.selected_columns["id"] == id)


            stmt = select(MyModel)

            # adds "WHERE id=:param" to the statement
            stmt = filter_on_id(stmt, 42)

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

        zCallable[[Any], str])rr�r�r�r:r�r%r^)r��convrW�ccs    r�r:zSelect.selected_columnssz��|�"��1�1�$�2C�2C�D�
��
9I��3�3�
�3�A�$�Q�'��a��!��3�
�9
���~�~����

s�A0c�b�tj|�j}t||��Sr�)r�rrWr�r�s  r�r�zSelect._all_selected_columns\s'���+�+�D�1�F�F���D��J��r�c�T�|jtur|jt�}|Sr�)r�r�rr�r�s r�rXz"Select._ensure_disambiguated_namesas'����� 0�0��'�'�(E�F�D��r�r;c��|r_|}t|jd�|�D���	�
��cgc].\\}}}	}
}}t|
�r|
j|||d|||����0}
}}
}	}}}nL|jd�D���	�
�cgc]*\}}}	}
}t|
�r|
j|||d||����,}
}
}	}}}|j	|
�ycc}}}
}	}}wcc}}
}	}}w)zYGenerate column proxies to place in the exported ``.c``
        collection of a subquery.FT)rgr��name_is_truncatable�compound_select_colsr�r�)rgr�rr�r�N)r�r�r%rQrV)r�r�r�r�r�r<rr�r�r�rWr��
extra_cols�proxs              r�r�z*Select._generate_fromclause_column_proxiesfs��"�!7��*��9�9�%�@�*��)��(�	��+�!�+�� ��%�Q�'�1�
�
��!�,�(,�)3� +�!-���&�)
��V�7�7��>��?�
�'��'���$�Q�'��
�
��!�,�(,� +�!-�
��?�
��&	�'�'��-��_��8s�3C�9/C
c�\�|jxst|jj�Sr�)r�r�r�r�r�s r��_needs_parens_for_groupingz!Select._needs_parens_for_grouping�s+���,�,�
���!�!�)�)�1
�	
r�c�\�t|t�r|j�s|St|�S)a@Return a 'grouping' construct as per the
        :class:`_expression.ClauseElement` specification.

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

        )r�r�r
rfrws  r�ryzSelect.self_group�s*��
�w��/��3�3�5��K�*�4�0�0r�c�.�tj|g|���S)a�Return a SQL ``UNION`` of this select() construct against
        the given selectables provided as positional arguments.

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

         .. versionchanged:: 1.4.28

            multiple elements are now accepted.

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

        )r�r�rEs  r�rzSelect.union�s��"�+�+�D�9�5�9�9r�c�.�tj|g|���S)a�Return a SQL ``UNION ALL`` of this select() construct against
        the given selectables provided as positional arguments.

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

         .. versionchanged:: 1.4.28

            multiple elements are now accepted.

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

        )r�r�rEs  r�rzzSelect.union_all����"�/�/��=�u�=�=r�c�.�tj|g|���S)a.Return a SQL ``EXCEPT`` of this select() construct against
        the given selectable provided as positional arguments.

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

         .. versionchanged:: 1.4.28

            multiple elements are now accepted.

        )r�r�rEs  r��except_zSelect.except_�s���,�,�T�:�E�:�:r�c�.�tj|g|���S)a3Return 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.

        )r�r�rEs  r��
except_allzSelect.except_all�s���0�0��>��>�>r�c�.�tj|g|���S)a�Return a SQL ``INTERSECT`` of this select() construct against
        the given selectables provided as positional arguments.

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

         .. versionchanged:: 1.4.28

            multiple elements are now accepted.

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

        )r�r�rEs  r��	intersectzSelect.intersectrr�c�.�tj|g|���S)a�Return a SQL ``INTERSECT ALL`` of this select() construct
        against the given selectables provided as positional arguments.

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

         .. versionchanged:: 1.4.28

            multiple elements are now accepted.

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

        )r�r�rEs  r��
intersect_allzSelect.intersect_alls��"�3�3�D�A�5�A�Ar�)r�rr�r})r��_ColumnsClauseArgument[Any]r`)r��_ColumnExpressionArgument[bool]r�r[)r�zFUnion[FromClause, _JoinTargetProtocol, ColumnElement[Any], TextClause])r�zSelect[Tuple[_MAYBE_ENTITY]]r�r�)r�zSelect[Tuple[_NOT_ENTITY]]r�zScalarSelect[_NOT_ENTITY]r�)r�rr�r[)r�r)r�rlr�r�r�)
r�r_r3rr4r�r5r�r�r[)
r�r^r�r_r3rr5r�r�r[)r�r^r�r_r3rr4r�r5r�r�r[)r�r_r3rr5r�r�r[)r�zSequence[FromClause]r�r�r�r)r�rr�zIterable[ClauseElement])r�rr�r})r�z%Iterable[_ColumnsClauseArgument[Any]]r�r�)r�rr�r})T)r�r�r�r})r��
_TCCA[_T0]r�r�r�zSelect[Tuple[_T0]])r�rr��
_TCCA[_T1]r�r�r�zSelect[Tuple[_T0, _T1]])
r�rr�rr��
_TCCA[_T2]r�r�r�zSelect[Tuple[_T0, _T1, _T2]])r�rr�rr�rr��
_TCCA[_T3]r�r�r�z!Select[Tuple[_T0, _T1, _T2, _T3]])r�rr�rr�rr�rr��
_TCCA[_T4]r�r�r�z&Select[Tuple[_T0, _T1, _T2, _T3, _T4]])r�rr�rr�rr�rr�r r��
_TCCA[_T5]r�r�r�z+Select[Tuple[_T0, _T1, _T2, _T3, _T4, _T5]])r�rr�rr�rr�rr�r r�r!r��
_TCCA[_T6]r�r�r�z0Select[Tuple[_T0, _T1, _T2, _T3, _T4, _T5, _T6]])r�rr�rr�rr�rr�r r�r!r�r"r�z
_TCCA[_T7]r�r�r�z5Select[Tuple[_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7]])r�rr�r�r�rr�r})r�r�)r�rr�r[)r�rr�r[)r#r�r�r[�rr^r�r[�r�z0Union[Literal[None, False], _FromClauseArgument]r�r[r[r|r\r�)rxr�r�z*Union[SelectStatementGrouping[Self], Self])rFrr�r	)dr�r�r�r�r�rrrr�r�rDrEr:r�rrr�r�rr�rSr��dp_memoized_select_entities�dp_clauseelement_tupler�rr
rr�rpr�r�r�r
rrrr+rzr>�_executable_traverse_internalsr��dp_has_cache_keyrrr�r�rMr�r�rrr�r�r�r�r&r4r6r�r�r8r�rWr�rr�r�r�r,r�r�r�r�r�r�r�r�r��_whereclauser�r�r�rrrrXr:r�rXr�r
ryrrzrrrrrrs@r�r-r-xs�
�����N�35�L�0�5�68��3�8�-�-��I�t��35�L�0�5�)+�J�&�+�:>��7�>�68�O�3�8�79��4�9�(*�I�%�*��O����2�2��&���.�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�
�,�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�
6�
6�1	7�2�
6�
6�3	7�4�
0�
0�5	1�6#�
H�
H�7	I�8�
3�
3�9	4��/��@4G�	�.�?�?�@�J�4��0��.�-��
��
�(� �%�
$�
�$�$�	�	$�.�	$�
�	$�
�	$�
�	,�,�	,�
&�	,�
�	,�
�;�
�;�;�%��)��)�V%�.�%�	�%�2�15�W�
��
W�#�W�.�W�
�W��
W�
�W��W�z15�	
��

�"�
�$�
�.�	
��

�
�
�&�
15�	K���K�"�K�$�K�.�	K��
K��K�
�K��K�`15�)M�
�)M�#�)M�.�)M�
�)M�
�
)M�V'P�R��T�_�_��	A��
&���&��
��
�(�
0��
0��+1�8#�'�8#�8;�8#�	
�8#�t
��"�4�"�	�"��"�H
�=�
�	
�
��T�_�_�
�	1��(�
�(� �T���.�/��0��L�CF�!� �!�<@�!�	�!��!��'*�&��&��&�
 $�&�
!�
&��&��'*�
+��+��+��	+� $�
+�
&�+��+��'*�0��0��0��	0�
�0� $�0�
+�0��0��'*�	5��	5��	5��		5�
�	5��
	5� $�	5�
0�	5��	5��'*�
:��
:��
:��	
:�
�
:��
:��
:� $�
:�
5�
:��
:��'*�?��?��?��	?�
�?��
?��?��?� $�?�
:�?��?��'*�D��D��D��	D�
�D��
D��D��D��D� $�D�
?�D��D� �',��.�� $���	�

�����',�M�.�M� $�M��	M�

�M��M�^�
��
� �L����� �����&��&�P�(��(�T�F�F�F�
�F��F�P�-�F�-�
�-��-�^'�I �	2�I �'�I �V'� �'� ��
�?.��?.�@�?.��	?.�
3�?.�!
�?.�
�?.�B
�15�1�-�1�	3�1�&:�>�:�	�:�&>�>�>�	�>�&;�>�;�	�;� ?�>�?�	�?� >�>�>�	�>�&B�>�B�	�Br�r-c��eZdZUdZdej
fdejfgZded<gZ	ded<dZ
esd	ZdZ
d
ed<dd�Zdd�Zdd
�Zdd�Zedd��ZeZedd��Zddd�Zerdd�Ze				dd��Ze				dd��Zy) rSa�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

    r!rrRr�r�r3TFr�c�^�||_|j�|_|j|_yr�)r!rMr�_propagate_attrsr�s  r�r�zScalarSelect.__init__Ls'������(�(�*��	� '� 8� 8��r�c�.�t|j|�Sr�)rIr!)r��attrs  r��__getattr__zScalarSelect.__getattr__Qs���t�|�|�T�*�*r�c�4�|j|jd�S)N�r!rr1r�s r�r�zScalarSelect.__getstate__Ts���<�<����;�;r�c�,�|d|_|d|_y)Nr!rr1r�s  r�r�zScalarSelect.__setstate__Ws���Y�'����&�M��	r�c�,�tjd��)NzcScalar Select expression has no columns; use this object directly within a column-level expression.)rVr?r�s r�r�zScalarSelect.columns[s���%�%�
0�
�	
r�c�Z�td|j�j|�|_|S)zuApply a WHERE clause to the SELECT statement referred to
        by this :class:`_expression.ScalarSelect`.

        r})rr!r�)r�r�s  r�r�zScalarSelect.wherees&���M�4�<�<�8�>�>�t�D����r�Nc��|Sr�r�rws  r�ryzScalarSelect.self_groupnr5r�c��yr�r�r�s r�rrzScalarSelect._ungroupss��3r�c�V�td|j�j|�|_|S)a�Return a new :class:`_expression.ScalarSelect`
        which will correlate the given FROM
        clauses to that of an enclosing :class:`_expression.Select`.

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

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

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

        .. seealso::

            :meth:`_expression.ScalarSelect.correlate_except`

            :ref:`tutorial_scalar_subquery` - in the 2.0 tutorial


        r})rr!rr�s  r�rzScalarSelect.correlateus.��>C�t�M�4�<�<�8�B�B�
�
����r�c�V�td|j�j|�|_|S)a�Return a new :class:`_expression.ScalarSelect`
        which will omit the given FROM
        clauses from the auto-correlation process.

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

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

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

        .. seealso::

            :meth:`_expression.ScalarSelect.correlate`

            :ref:`tutorial_scalar_subquery` - in the 2.0 tutorial


        r})rr!rr�s  r�rzScalarSelect.correlate_except�s/��BJ�t�M�4�<�<�8�I�I�
�
����r�)r!r�r�r�)r.rr�r)r�r)r�rr�r�rk)r�rr�r[r�r�r|r$)r�r�r�r�rSrrYr�rr3r=r�_is_implicitly_booleanr�r�r/r�r�r�r�rWr4r�ryrrrrr�r�r�rSrS,s����"
�%�6�6�7�	�"�*�*�+�3��/��
')�M�#�(����!&���M�
��9�
+�<�"��
��
�	�A�������.��!�F�!�
�!��!�F�#�F�#�
�#��#r�rSc��eZdZUdZdZded<	d	dd�Zejdd��Z					dd�Z
dd	�Z				dd
�Z				dd�Z
dd�Zdd
�Zy)rPz�Represent 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`.

    Tz>Union[SelectStatementGrouping[Select[Any]], ScalarSelect[Any]]r!Nc�v�|�#ttd��j�}n^t|t�r"|j�}|j
|_n,t|t�r|}nt|�j�}tj||tjtjd��y)Nr�T)�operatorr��wraps_column_expression)
r-rMr�r�r�r,rSrOr�rrQr�BOOLEANTYPE)r��_Exists__argumentr�s   r�r�zExists.__init__�s������~�c�*�+�;�;�=�A�
�
�J�
/��*�*�,�A�!+�!<�!<�A��
�
�L�
1��A��z�"�2�2�4�A�� � ��
��%�%��&�&�$(�	
r�c��gSr�r�r�s r�r3zExists._from_objects�s���	r�c��|jj�}||�}|jtj��}t|t�sJ�|S)Nr�)r!rrryrrQr�rf)r��fnr!rj�return_values     r��_regroupzExists._regroup�sO���,�,�'�'�)����k��"�-�-�i�6F�6F�-�G���,�(?�@�@�@��r�c��t|�S)a�Return a SELECT of this :class:`_expression.Exists`.

        e.g.::

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

        This will produce a statement resembling:

        .. sourcecode:: sql

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

        .. seealso::

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

        r,r�s r�r.z
Exists.select�s��(�d�|�r�c�Z��|j�}|j�fd��|_|S)z�Apply correlation to the subquery noted by this
        :class:`_sql.Exists`.

        .. seealso::

            :meth:`_sql.ScalarSelect.correlate`

        c�"��|j��Sr�)r�r!r�s �r�r�z"Exists.correlate.<locals>.<lambda>s���-�G�-�-�{�;r��r,rDr!�r�r�r�s ` r�rzExists.correlates*���
�K�K�M���M�M�;�
��	��r�c�Z��|j�}|j�fd��|_|S)z�Apply correlation to the subquery noted by this
        :class:`_sql.Exists`.

        .. seealso::

            :meth:`_sql.ScalarSelect.correlate_except`

        c�"��|j��Sr�)rrHs �r�r�z)Exists.correlate_except.<locals>.<lambda>-s���4�G�4�4�k�Br�rIrJs ` r�rzExists.correlate_excepts*���
�K�K�M���M�M�B�
��	��r�c�Z��|j�}|j�fd��|_|S)a�Return a new :class:`_expression.Exists` construct,
        applying the given
        expression to the :meth:`_expression.Select.select_from`
        method of the select
        statement contained.

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

        c�"��|j��Sr�)r)r!rs �r�r�z$Exists.select_from.<locals>.<lambda>?s���2E�'�2E�2E�u�2Mr�rI)r�rr�s ` r�rzExists.select_from1s&���
�K�K�M���M�M�"M�N��	��r�c�Z��|j�}|j�fd��|_|S)a�Return a new :func:`_expression.exists` construct with the
        given expression added to
        its WHERE clause, joined to the existing clause via AND, if any.


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

        c�"��|j��Sr�r�)r!r�s �r�r�zExists.where.<locals>.<lambda>Os���-�'�-�-��2Hr�rI)r�r�r�s ` r�r�zExists.whereBs&���
�K�K�M���M�M�"H�I��	��r�r�)r?zKOptional[Union[_ColumnsClauseArgument[Any], SelectBase, ScalarSelect[Any]]]r�)rBz$Callable[[Select[Any]], Select[Any]]r�z$SelectStatementGrouping[Select[Any]])r�zSelect[Tuple[bool]]r$r#)r�rr�r[)r�r�r�r�r�rr�rWr�r3rDr.rrrr�r�r�r�rPrP�s�����M�
K�K�
�	
�
�
�6
�"�"��#���6��	-���,�F��
��$�F��
��&�"r�rPc�f�eZdZUdZdZeZdejfdejfge
jzejzZded<dZdZdZ	d							dd�Z	d							dd	�Ze		dd
��Zej0dd��Zdd�Zdd
�Ze						dd��Zdd�											dd�Zdd�Zy)�
TextualSelectaFWrap 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_argsrRr�Tc
��|j||D�cgc]&}tjtj|���(c}|�ycc}wr�)r$rrr�LabeledColumnExprRole)r�rr��
positionalrWs     r�r�zTextualSelect.__init__�sM��	
�
�
��!�
� �A�� � ��!<�!<�a�@� �
�
�	
��
s�+A
c�.�||_||_||_yr�)r!rTrW)r�rr�rWs    r�r$zTextualSelect._init�s�����"���$��r�c�V�td�|jD��j�S)amA :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

        c3�8K�|]}|j|f���y�wr�r�rks  r�rTz1TextualSelect.selected_columns.<locals>.<genexpr>�s���� 
� 0�1�Q�U�U�A�J� 0�r�)r:rTr^r�s r�r:zTextualSelect.selected_columns�s+��0 � 
� $� 0� 0� 
�
�
�+�-�	r�c��|jSr�)rTr�s r�r�z#TextualSelect._all_selected_columns�s�����r�c��|Sr�r�rGs  r�rzTextualSelect.set_label_style�r5r�c��|Sr�r�r�s r�rXz)TextualSelect._ensure_disambiguated_names�r5r�c�H�|jj|i|��|_|Sr�)r!�
bindparams)r��binds�bind_as_valuess   r�r_zTextualSelect.bindparams�s&��/�t�|�|�.�.��H��H����r�Nr;c������trt�t�sJ�|r1|j���fd�t	|j
|�D��y|j���fd�|j
D��y)Nc3�N�K�|]\}}|j�|�������y�w))r	r�r�NrP)rRrWr
r�r�r�s   ���r�rTzDTextualSelect._generate_fromclause_column_proxies.<locals>.<genexpr>�s;�����
,�&�M�A�z�
�
�
��)3� +�!-�	��&�s�"%c3�F�K�|]}|j��������y�wrNrP)rRrWr�r�r�s  ���r�rTzDTextualSelect._generate_fromclause_column_proxies.<locals>.<genexpr>�s4�����,�*�A��
�
�� +�!-���
*�rU)rr�r�rVr�rT)r�r�r�r�r�r<s ` `` r�r�z1TextualSelect._generate_fromclause_column_proxies�sn�����j�(�3�3�3�!��+�+�
,�&)��$�$�&<�&�
,�

�
�+�+�,��)�)�
,�
r�c�4�|jdjSr�)rTrr�s r�rMzTextualSelect._scalar_type�s������"�'�'�'r�r�)rr{r�z$List[_ColumnExpressionArgument[Any]]rWr�r�r�)rr{r�zList[NamedColumn[Any]]rWr�r�r�)r�r�r�)rHr�r�rR)r�rR)r`zBindParameter[Any]rarr�r[)r�r�r�r�r�r;r�r�r<r]r�r�)r�zUnion[TypeEngine[Any], Any]) r�r�r�r�r�r�r�rSrr�r+rzrpr�r�r�_is_textual�is_textrbr�r$rXr:rWr�r�rrXr4r_r�rMr�r�r�rRrRSs����6&�N�#�L��)�:�:�;�
�-�C�C�D�	
�#�
H�
H�		I�
�
-�
-�	.��/���K��G��I�!�	
��
�6�
��	
�

�
�(!�	%��%�(�%��	%�

�%�'��	7��'��6
�"�"� �#� �����"����
�	���"
�"��"�@�"��	"�
3�"�!
�"�
�"�H(r�rRc�F��eZdZd�fd�Zej
dd��Z�xZS)�AnnotatedFromClausec���t�|�di|��|jdd�r7|j}|jj
j
|�|_yy)N�ind_cols_on_fromclauseFr�)r�r�r|�_Annotated__elementrJrW�fget)r�r��eerJs   �r�r�z#AnnotatedFromClause._copy_internals�sL���
���%�"�%�
�6�6�*�E�2��)�)�B��\�\�^�^�(�(��.�D�F�3r�c�2�|j}|jS)aoproxy the .c collection of the underlying FromClause.

        Originally implemented in 2008 as a simple load of the .c collection
        when the annotated construct was created (see d3621ae961a), in modern
        SQLAlchemy versions this can be expensive for statements constructed
        with ORM aliases.   So for #8796 SQLAlchemy 2.0 we instead proxy
        it, which works just as well.

        Two different use cases seem to require the collection either copied
        from the underlying one, or unique to this AnnotatedFromClause.

        See test_selectable->test_annotated_corresponding_column

        )rlrW)r�rns  r�rWzAnnotatedFromClause.c�s�� �
%�
%���t�t�r�)r�rr�r�r�)r�r�r�r�rWr�rWrrs@r�riri�s"���/�
�����r�ri)�r��
__future__rr��enumrr��typingrrrrrr	r
rrr
rrrrrrrrrrrr�rrrrrrr �_typingr!r"r#r$r%r&r'r(r)�
annotationr*r+�baser,r-r.r/r0r1r3r4r6r7r8r9r:r;r<r=r>r?r@rArBrCr�rDrErFrGrHrIrJrKrLrMrNrOrP�sqltypesrQrRrSrTrVrWrX�util.typingrYrZr[r�r\r]r^r_r`rarbrcrdrerfrgrhrirjrkrlrmrn�_TCCArorprqrrrsrrt�dmlrurvrwrxryrzr{rfr|r*r}r~rr�r��_ColumnsClauseElementrrmr�rq�_OnClauseElement�_ForUpdateOfArgument�_SetupJoinsElementr�rr�r)r�r�r�r�r�r
r�AnonymizedFromClauseRoler�r�r�r�r�r�r�rr��DMLTableRoler1rr�r rAr�rHr�r?r�rjr�r�r�rrrpr�r�r�r�r�rr��
InElementRolerr)r��
DMLSelectRoler�r�rcrfr}�
plugin_forr�r�r�r�setattrr��
MemoizedSlotsr�rt�HasCacheKey�HasCopyInternals�Traversiblerxr-rSrPrR�
TextAsFromrir�r�r��<module>r�s����#�����"����������������� ����������+����&�(� ��#�!�0��$�&�'�"� ���&��#�"�"���(���!���.�&�#�'�#� �"�#�)�$�$�'�%�#��,�'�%���4�!�"�������2�<�,�,�)�&�$�*�<���������7�<�,�,�&�.�1�%���*�,��%�$�#�"�,�(�$�,��l�M�#�,>��L�M��#�
�-�.�/��#��>���
8�(�8��<�)<�<�=���.�0C�C�D���	�	��

�
-�.�0������
���\����c��N�����5�!C�D�E��$�
�c�*�$�U$�%�'�'�)<�U$�p;�J��;�C�,�g�c�l�C�K
��K
�\0�0�f1�1�h{�{�|A,��/�/��A,�H)<�j�)<�Xs�t�s�v	�	����"�!��4��oN�5���z�oN�d

�
�I��I�`���`�F�(��!&�E����!&�Hu�(�%�u�p�o�0��B7�/�7�tBF�	���	�O�O�����
BF�J�z���
��Bk�+�k�\a
�U�
�
�{�a
�H
:P�!�:P�z;�>�:�;�|
��o�
� \�%�$�$�i��\�~�>�4��t�C��H�~�E�F��C�=�C�LP�U�
 �
 �*�.?�P�f+�5�&�&��
�c�8J�+�\G(�	���	���	���	���
���G(�T
�e�:�&��e"�n�j�'�#�,�e"�Po�z�:�o�d�����$5�6�
�,�
�7�
� $�T�$�Q0�_�&6�8H��8M�Q0�j
#�D��N�D�I�I�t�,�
#������H�-�\&�$�$�$�l�\&�.�\&�~��>7F�
���:�6�6��8L�8L�7F�tqB��������S��qB�h-Q�	����^�]�2�5F�Q�hP�_�T�
"�P�f\(�J� 5�z�\(�~�
�4��)�r�

if you don't want to be vaporized in a nuclear explosion, i simply have to become nuclear myself… i am atomic