Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/sql/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/sql/__pycache__/selectable.cpython-311.pyc

�

�܋f�!��l�dZddlZddlZddlZddlmZddlmZddlmZddlm	Z	ddl
mZdd	lm
Z
dd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$dd lm%Z%dd!lm&Z&dd"lm'Z'dd#lm(Z(dd$lm)Z)d%d&lm*Z*d%d'lm+Z+d%d(lm,Z,d)�Z-d*�Z.Gd+�d,e#��Z/dZd-�Z0d.�Z1d/�Z2Gd0�d1e$��Z3Gd2�d3e4��Z5Gd4�d5e4��Z6Gd6�d7e3��Z7Gd8�d9e7��Z8Gd:�d;e7��Z9Gd<�d=e9��Z:Gd>�d?e9��Z;Gd@�dAee5e6e9��Z<GdB�dCe4��Z=GdD�dEe7��Z>GdF�dGee7��Z?GdH�dIe$��Z@GdJ�dKe=ee7��ZAGdL�dMeA��ZBGdN�dOeB��ZCGdP�dQe5e6eB��ZDGdR�dSee&��ZEGdT�dUe)��ZFGdV�dWeA��ZGGdX�dYe��ZHdS)[ztThe :class:`_expression.FromClause` class of SQL expression elements,
representing
SQL tables and derived rowsets.

�N)�
attrgetter)�	Visitable�)�	operators)�type_api)�	Annotated)�
_from_objects)�_generative)�ColumnCollection)�	ColumnSet)�
Executable)�
Generative)�	Immutable)�_anonymous_label)�_clause_element_as_expr)�_clone)�_cloned_difference��_cloned_intersection)�_document_text_coercion)�_expand_cloned��_interpret_as_column_or_from)�&_literal_and_labels_as_label_reference��_literal_as_label_reference��_literal_as_text)�_no_text_coercion)�_select_iterables)�and_)�
BindParameter)�
ClauseElement)�
ClauseList)�Grouping)�literal_column)�True_)�UnaryExpression�)�exc)�
inspection)�utilc��tj|d���}|�)t|tj��rt|��	|jS#t$r3}tjtj
d��|���Yd}~dSd}~wwxYw)NF)�raiseerrzFROM expression expected��replace_context)r+�inspect�
isinstancer,�string_typesr�
selectable�AttributeError�raise_r*�
ArgumentError)�element�insp�errs   �P/opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/sql/selectable.py�_interpret_as_fromr<8s�����g��6�6�6�D��|��g�t�0�1�1�	'��g�&�&�&�
������
�
�
�����8�9�9�3�	
�	
�	
�	
�	
�	
�	
�	
�	
�	
�����
���s�A
�

B�(B�Bc��t|��}t|t��r|j}t|t��s|���}|S�N)r<r2�Alias�original�
SelectBase�select�r8s r;�_interpret_as_selectrDEsO�� ��)�)�G��'�5�!�!�#��"���g�z�*�*�#��.�.�"�"���N�c�$�eZdZed���ZdS)�_OffsetLimitParamc��|jSr>)�effective_value��selfs r;�_limit_offset_valuez%_OffsetLimitParam._limit_offset_valueOs���#�#rEN)�__name__�
__module__�__qualname__�propertyrL�rEr;rGrGNs-������
�$�$��X�$�$�$rErGc���|�dSt|d��r|���St|t��r|St	j|��}t
|||d���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.

    N�__clause_element__T)�type_�unique)�hasattrrSr2rr,�asintrG)r8�namerT�values    r;�_offset_or_limit_clauserZTsr�����t�	��.�	/�	/�H��)�)�+�+�+�	�G�Y�	'�	'�H����
�7�#�#�� ��u�E�$�G�G�G�GrEc���|�dS	|j}tj|��S#t$r6}tjtjd|z��|���Yd}~dSd}~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 %sr/)rLr,rWr5r6r*�CompileError)�clause�attrnamerYr:s    r;�_offset_or_limit_clause_asintr_fs����~��t�!��*���z�%� � � ���
�
�
�����'�)1�2�
�
� �	
�	
�	
�	
�	
�	
�	
�	
�	
�	
�����
���s�!�
A!�+A�A!c�@�t|i|���|��S)z�Return an :class:`_expression.Alias` object derived
    from a :class:`_expression.Select`.

    :param alias: the alias name

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

    )�Select�alias)rb�args�kwargss   r;�subqueryre~s%���4�"�6�"�"�(�(��/�/�/rEc�0�eZdZdZdZdZed���ZdS)�
Selectablez!Mark a class as being selectable.r4Tc��|Sr>rQrJs r;r4zSelectable.selectable�s���rEN)rMrNrO�__doc__�__visit_name__�
is_selectablerPr4rQrEr;rgrg�s=������+�+�!�N��M�
����X���rErgc�V�eZdZdZeeddd��d�����Zdd�ZdS)	�HasPrefixesrQ�exprz+:meth:`_expression.HasPrefixes.prefix_with`z*:paramref:`.HasPrefixes.prefix_with.*expr`c��|�dd��}|r*tjdd�|��z���|�||��dS)a�Add one or more expressions following the statement keyword, i.e.
        SELECT, INSERT, UPDATE, or DELETE. Generative.

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

        E.g.::

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

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

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

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

        �dialectN�Unsupported argument(s): %s�,)�popr*r7�join�_setup_prefixes�rKrn�kwrps    r;�prefix_withzHasPrefixes.prefix_with�se��B�&�&��D�)�)��
�	��#�-�������<���
�	
���T�7�+�+�+�+�+rENc�X��|jt�fd�|D����z|_dS)Nc�6��g|]}t|d����f��S�T)�allow_coercion_to_textr��.0�prps  �r;�
<listcomp>z/HasPrefixes._setup_prefixes.<locals>.<listcomp>��;���
�
�
��"�!�D�A�A�A�7�K�
�
�
rE)�	_prefixes�tuple)rK�prefixesrps  `r;ruzHasPrefixes._setup_prefixes��G�����%�
�
�
�
�!�
�
�
�+
�+
�
����rEr>)rMrNrOr�r
rrxrurQrEr;rmrm�sj�������I�����5�4���
 ,� ,����[� ,�D
�
�
�
�
�
rErmc�V�eZdZdZeeddd��d�����Zdd�ZdS)	�HasSuffixesrQrnz+:meth:`_expression.HasSuffixes.suffix_with`z*:paramref:`.HasSuffixes.suffix_with.*expr`c��|�dd��}|r*tjdd�|��z���|�||��dS)aAdd one or more expressions following the statement as a whole.

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

        E.g.::

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

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

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

        rpNrqrr)rsr*r7rt�_setup_suffixesrvs    r;�suffix_withzHasSuffixes.suffix_with�sd��8�&�&��D�)�)��
�	��#�-�������<���
�	
���T�7�+�+�+�+�+rENc�X��|jt�fd�|D����z|_dS)Nc�6��g|]}t|d����f��Sr{rr}s  �r;r�z/HasSuffixes._setup_suffixes.<locals>.<listcomp>�r�rE)�	_suffixesr�)rK�suffixesrps  `r;r�zHasSuffixes._setup_suffixes�r�rEr>)rMrNrOr�r
rr�r�rQrEr;r�r��si�������I�����5�4���
,�,����[�,�:
�
�
�
�
�
rEr�c��eZdZdZdZdZgZdZdZdZ	dZ
dZ	dZ	d�Z
ejdg��Zejdd�	��ejd
��d$d�����Zd$d�Zd%d
�Zd&d�Zd&d�Zd$d�Zd'd�Zd�Zd�Zejd��d���Zd�Zd(d�Zed���Z d�Z!ed���Z"ed���Z#ed���Z$ee%d��d���Z&ee%d����Z'd �Z(ed!���Z)d"�Z*d#�Z+dS))�
FromClauseaERepresent 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`.


    �
fromclauseFNc��|Sr>rQ)rK�effective_schema�map_s   r;�_translate_schemazFromClause._translate_schema's���rE�_columnsz1.1z�The :meth:`.FromClause.count` method is deprecated, and will be removed in a future release.   Please use the :class:`_functions.count` function available from the :attr:`.func` namespace.��message�sqlalchemy.sql.functionsc���|jrt|j��d}nt|j��d}t|j�|���d��g|fd|gi|��S)z�Return a SELECT COUNT generated against this
        :class:`_expression.FromClause`.

        .. seealso::

            :class:`_functions.count`

        r�
tbl_row_count�from_obj)�primary_key�list�columnsra�func�count�label)rK�	functions�whereclause�params�cols     r;r�zFromClause.count,s���$��	(��t�'�(�(��+�C�C��t�|�$�$�Q�'�C��
�^�
!�
!�#�
&�
&�
,�
,�_�
=�
=�>��
�
��V�
��	
�
�	
rEc� �t|g|fi|��S)z�Return a SELECT of this :class:`_expression.FromClause`.

        .. seealso::

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

        �ra�rKr�r�s   r;rBzFromClause.selectIs���t�f�k�4�4�V�4�4�4rEc�(�t|||||��S)a�Return a :class:`_expression.Join` from this
        :class:`_expression.FromClause` to another
        :class:`_expression.FromClause`.

        E.g.::

            from sqlalchemy import join

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

        would emit SQL along the lines of::

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

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

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

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

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

         .. versionadded:: 1.1

        .. seealso::

            :func:`_expression.join` - standalone function

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

        ��Join)rK�right�onclause�isouter�fulls     r;rtzFromClause.joinUs��X�D�%��7�D�9�9�9rEc�(�t|||d|��S)aReturn a :class:`_expression.Join` from this
        :class:`_expression.FromClause`
        to another :class:`FromClause`, with the "isouter" flag set to
        True.

        E.g.::

            from sqlalchemy import outerjoin

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

        The above is equivalent to::

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

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

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

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

         .. versionadded:: 1.1

        .. seealso::

            :meth:`_expression.FromClause.join`

            :class:`_expression.Join`

        Tr�)rKr�r�r�s    r;�	outerjoinzFromClause.outerjoin�s��X�D�%��4��6�6�6rEc�8�t�||��S)asReturn 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:`core_tutorial_aliases`

            :func:`_expression.alias`

        )r?�
_construct�rKrX�flats   r;rbzFromClause.alias�s��&����d�+�+�+rEc�8�t�||��S)aMReturn a LATERAL alias of this :class:`_expression.FromClause`.

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

        .. versionadded:: 1.1

        .. seealso::

            :ref:`lateral_selects` -  overview of usage.

        )�Lateralr��rKrXs  r;�lateralzFromClause.lateral�s���!�!�$��-�-�-rEc�<�t�||||��S)avReturn a TABLESAMPLE alias of this :class:`_expression.FromClause`.

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

        .. versionadded:: 1.1

        .. seealso::

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

        )�TableSampler�)rK�samplingrX�seeds    r;�tablesamplezFromClause.tablesample�s���%�%�d�H�d�D�A�A�ArEc��||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_set�rKr�s  r;�is_derived_fromzFromClause.is_derived_from�s���T�-�-�-rEc�@�|j�|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��intersection�rK�others  r;�_is_lexical_equivalentz!FromClause._is_lexical_equivalent�s����,�,�U�->�?�?�?rE�sqlalchemy.sql.utilc�R�|�|���|��S)z�Replace all occurrences of FromClause 'old' with the given Alias
        object, returning a copy of this :class:`_expression.FromClause`.

        )�
ClauseAdapter�traverse)rK�sqlutil�oldrbs    r;�replace_selectablezFromClause.replace_selectable�s&���$�$�U�+�+�4�4�T�:�:�:rEc��|�|d���}|�,||vr(||D]}|�|d���}|r|cS� |S)zzReturn corresponding_column for the given column, or if None
        search for a match in the given dictionary.

        T)�require_embedded)�corresponding_column)rK�column�equivalentsr��equiv�ncs      r;�correspond_on_equivalentsz$FromClause.correspond_on_equivalentssr��
�'�'���'�F�F���;�3�+�-�-�$�S�)�
�
���.�.�u�t�.�L�L�����I�I�I���
rEc�x��d�}|j����r�Sd\}}�j}|jj}|D]�}t	t|j����}	|�|	��}
|
r�|r||	|��r�|�||
}}�Ot|
��t|��kr||
}}�t|
|kr�tj	tj�fd�|���D����}tj	tj�fd�|���D����}||kr||
}}��|S)aXGiven a :class:`_expression.ColumnElement`, return the exported
        :class:`_expression.ColumnElement` object from this
        :class:`expression.Selectable`
        which corresponds to that original
        :class:`~sqlalchemy.schema.Column` 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.FromClause`.
         Normally the column will match if
         it merely shares a common ancestor with one of the exported
         columns of this :class:`_expression.FromClause`.

        c��|�|��D]5}tt|g�����|��sdS�6dS)NFT)�
difference�setrr�)�expanded_proxy_set�
target_set�ts   r;�embeddedz1FromClause.corresponding_column.<locals>.embedded'sb���*�*�+=�>�>�
!�
!���>�1�#�.�.�/�/�<�<�&���!�!�5�5�!��4rE�NNNc�p��g|]2}|�����|j�dd����3S��weightr��shares_lineage�_annotations�get�r~�scr�s  �r;r�z3FromClause.corresponding_column.<locals>.<listcomp>W�O������ "�!�0�0��8�8���O�/�/��!�<�<���rEc�p��g|]2}|�����|j�dd����3Sr�r�r�s  �r;r�z3FromClause.corresponding_column.<locals>.<listcomp>_r�rE)
�c�contains_column�	proxy_set�_all_columnsr�rr��lenr,�reduce�operator�add�_uncached_proxy_set)
rKr�r�r�r��	intersectr��colsr�r��i�col_distance�
c_distances
 `           r;r�zFromClause.corresponding_columns����,	�	�	��6�!�!�&�)�)�	��M�#���Y��%�
��v�"���1	.�1	.�A�!$�^�A�K�%@�%@�!A�!A���'�'�(:�;�;�A��.
.�$�.
.��8�.�
�;�;�.
.��;�&'���C�C���V�V�c�)�n�n�,�,�&'���C�C��)�^�^�$(�;� ������&)�&=�&=�&?�&?����$�$�L�"&�� ������&'�&;�&;�&=�&=����"�"�J�"�L�0�0�)*�A�Y����
rEc�>�t|d|jjdz��S)z|A brief description of this :class:`_expression.FromClause`.

        Used primarily for error message formatting.

        rXz object)�getattr�	__class__rMrJs r;�descriptionzFromClause.descriptionis ���t�V�T�^�%<�y�%H�I�I�IrEc�:�|j�|��dS)z8Delete memoized collections when a FromClause is cloned.N)�_memoized_property�expire_instancerJs r;�_reset_exportedzFromClause._reset_exportedrs!��	
��/�/��5�5�5�5�5rEc��d|jvr(|���|���|j���S)a�A named-based collection of :class:`_expression.ColumnElement`
        objects
        maintained by this :class:`_expression.FromClause`.

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

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

        r�)�__dict__�_init_collections�_populate_column_collectionr��as_immutablerJs r;r�zFromClause.columnswsI���T�]�*�*��"�"�$�$�$��,�,�.�.�.��}�)�)�+�+�+rEc�`�|���|���|jS)z}Return the collection of :class:`_schema.Column` objects
        which comprise the primary key of this FromClause.

        )rrr�rJs r;r�zFromClause.primary_key�s1��	
��� � � ��(�(�*�*�*���rEc�`�|���|���|jS)zpReturn the collection of :class:`_schema.ForeignKey` objects
        which this FromClause references.

        )rr�foreign_keysrJs r;r	zFromClause.foreign_keys�s1��	
��� � � ��(�(�*�*�*�� � rEr�z,An alias for the :attr:`.columns` attribute.)�docc��d|jvsJ�d|jvsJ�d|jvsJ�t��|_t��|_t��|_dS)Nr�r�r	)rrr�rr�r�r	rJs r;rzFromClause._init_collections�sf�����.�.�.�.��D�M�1�1�1�1��T�]�2�2�2�2�(�*�*��
�$�;�;����E�E����rEc��d|jvS)Nr�)rrJs r;�_cols_populatedzFromClause._cols_populated�s���T�]�*�*rEc��dS)z�Called on subclasses to establish the .c collection.

        Each implementation has a different way of establishing
        this collection.

        NrQrJs r;rz&FromClause._populate_column_collection�s���rEc�`�|jsdS|j|jvr|j|j|ur|SdS)aMGiven 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 ultimtely derives from.

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

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

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

        N)r
�keyr��rKr�s  r;�_refresh_for_new_columnz"FromClause._refresh_for_new_column�s@��2�#�	��4�
�Z�4�<�
'�
'�D�L���,D��,N�,N��M��4rEr>�NFF�NFr��F),rMrNrOrirj�named_with_column�_hide_froms�_is_join�
_is_select�_is_from_container�_is_lateral�_textual�schemar�r,�!group_expirable_memoized_propertyr��
deprecated�dependenciesr�rBrtr�rbr�r�r�r�r�r�r�rPr�rr�r�r	rr��_select_iterablerr
rrrQrEr;r�r��s���������("�N����K��H��J����K��H���F�� � � �@��?���M�M���T�_�
�#�����T��1�2�2�
�
�
�3�2���
�*
5�
5�
5�
5�,:�,:�,:�,:�\,7�,7�,7�,7�\,�,�,�,�*
.�
.�
.�
.�B�B�B�B� 
.�
.�
.�@�@�@��T��,�-�-�;�;�.�-�;����V�V�V�V�p�J�J��X�J�6�6�6�
�,�,���,�$� � ��� ��!�!���!�	���
�9���:�	�	�	�A� �x�
�
�9� 5� 5�6�6��"�"�"��+�+��X�+��������rEr�c��eZdZdZdZdZdd�Zedd���Ze	dd���Z	e
d	���Zd
�Zdd�Z
ejd��d
���Zd�Zefd�Zd�Zd�Zeejd���			d d�����Zedd���Zeejd��d�����Zed���Zdd�Ze
d���Zejd��dd���Ze
d���Ze
d���ZdS)!r�a�Represent a ``JOIN`` construct between two
    :class:`_expression.FromClause` elements.

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

    .. seealso::

        :func:`_expression.join`

        :meth:`_expression.FromClause.join`

    rtTNFc���t|��|_t|�����|_|�&|�|j|j��|_n||_||_||_dS)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)r<�left�
self_groupr��_match_primariesr�r�r�)rKr$r�r�r�r�s      r;�__init__z
Join.__init__�sj��'�t�,�,��	�'��.�.�9�9�;�;��
��� �1�1�$�)�T�Z�H�H�D�M�M�$�D�M������	�	�	rEc�"�||||d|���S)a�Return an ``OUTER JOIN`` clause element.

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

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

        :param left: The left side of the join.

        :param right: The right side of the join.

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

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

        T�r�r�rQ)�clsr$r�r�r�s     r;�_create_outerjoinzJoin._create_outerjoins��0�s�4���$�T�B�B�B�BrEc� �||||||��S)a8Produce a :class:`_expression.Join` object, given two
        :class:`_expression.FromClause`
        expressions.

        E.g.::

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

        would emit SQL along the lines of::

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

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

        :param left: The left side of the join.

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

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

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

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

         .. versionadded:: 1.1

        .. seealso::

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

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

        rQ)r*r$r�r�r�r�s      r;�_create_joinzJoin._create_joins��h�s�4���'�4�8�8�8rEc��d|jjt|j��|jjt|j��fzS)Nz Join object on %s(%d) and %s(%d))r$r��idr�rJs r;r�zJoin.descriptionTs:��1��I�!��t�y�M�M��J�"��t�z�N�N�	5
�
�	
rEc�r�||up3|j�|��p|j�|��Sr>)r$r�r�r�s  r;r�zJoin.is_derived_from]s?���$��
6��y�(�(��4�4�
6��z�)�)�*�5�5�	
rEc� �t|��Sr>��FromGrouping�rK�againsts  r;r%zJoin.self_groupd����D�!�!�!rEr�c��d�|jjD��d�|jjD��z}|j�|�d�|D��|j����|j�d�|D����|j	�tjd�|D�����dS)Nc��g|]}|��SrQrQ�r~r�s  r;r�z4Join._populate_column_collection.<locals>.<listcomp>is��0�0�0��1�0�0�0rEc��g|]}|��SrQrQr9s  r;r�z4Join._populate_column_collection.<locals>.<listcomp>is%��4
�4
�4
��A�4
�4
�4
rEc3�(K�|]
}|j�	|V��dSr>)r�r9s  r;�	<genexpr>z3Join._populate_column_collection.<locals>.<genexpr>os)����5�5�q�q�}�5��5�5�5�5�5�5rEc3�(K�|]
}|j|fV��dSr>)�_label�r~r�s  r;r<z3Join._populate_column_collection.<locals>.<genexpr>rs)����B�B�3�c�j�#�.�B�B�B�B�B�BrEc��g|]	}|j��
SrQ)r	r?s  r;r�z4Join._populate_column_collection.<locals>.<listcomp>ts��B�B�B�3�c�.�B�B�BrE)r$r�r�r��extend�reduce_columnsr�r��updater	�	itertools�chain)rKr�r�s   r;rz Join._populate_column_collectiongs���0�0�d�i�/�0�0�0�4
�4
��z�)�4
�4
�4
�
��	
�����"�"�5�5�G�5�5�5�t�}�
�
�	
�	
�	
�
	
�
���B�B�'�B�B�B�B�B�B��� � ��O�B�B�'�B�B�B�C�	
�	
�	
�	
�	
rEc�&�|j�|��}|�|j�|��}|�X|jrQ||j|j<|j�|j��|jr|j�	|��|SdSr>)
r$rr�r
r�r>r	rCr�r��rKr�r�s   r;rzJoin._refresh_for_new_columnws����i�/�/��7�7���;��*�4�4�V�<�<�C��?��#�
�,/��
�c�j�)��!�(�(��)9�:�:�:��?�.��$�(�(��-�-�-��
��trEc��|���||jfi|��|_||jfi|��|_||jfi|��|_dSr>)rr$r�r��rK�clonerws   r;�_copy_internalszJoin._copy_internals�si���������E�$�)�*�*�r�*�*��	��U�4�:�,�,��,�,��
���d�m�2�2�r�2�2��
�
�
rEc�*�|j|j|jfSr>)r$r�r��rKrds  r;�get_childrenzJoin.get_children�s���y�$�*�d�m�3�3rEc�p�t|t��r|j}nd}|�|||���S)N)�a_subset)r2r�r��_join_condition)rKr$r��
left_rights    r;r&zJoin._match_primaries�s=���d�D�!�!�	���J�J��J��#�#�D�%�*�#�E�E�ErE)�0.9z�The :paramref:`.join_condition.ignore_nonexistent_tables` parameter is deprecated and will be removed in a future release.  Tables outside of the two tables being handled are no longer considered.)�ignore_nonexistent_tablesc���|�||||��}t|��dkr|�||||��t|��dkrAt|t��rd}nd}tjd|j�d|j�d|�����d�t|�	����dD��}t|��dkr|dSt|�S)	a�Create a join condition between two tables or selectables.

        e.g.::

            join_condition(tablea, tableb)

        would produce an expression along the lines of::

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

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

        :param ignore_nonexistent_tables: unused - tables outside of the
         two tables being handled are not considered.

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

        rrzI Perhaps you meant to convert the right side to a subquery using alias()?�z2Can't find any foreign key relationships between '�' and 'z'.c� �g|]\}}||k��SrQrQ)r~�x�ys   r;r�z(Join._join_condition.<locals>.<listcomp>�s ��C�C�C�T�Q���a��C�C�CrE)�_joincond_scan_left_rightr��_joincond_trim_constraintsr2r3r*�NoForeignKeysErrorr�r��valuesr!)	r*�a�brTrP�consider_as_foreign_keys�constraints�hint�crits	         r;rQzJoin._join_condition�s��V�3�3�
�x��4�
�
���{���a����*�*��1�k�#;�
�
�
��{���q� � ��!�\�*�*�
�.���
���(�(��=�=�=�!�-�-�-���7���
�D�C�T�+�*<�*<�*>�*>�%?�%?��%B�C�C�C���t�9�9��>�>���7�N���;�rEc��t|t��r|j}nd}|�||||���}t	|��S)N)r_r`rPra)r2r�r�r[�bool)r*r$r�rarRrbs      r;�	_can_joinzJoin._can_join�sX���d�D�!�!�	���J�J��J��3�3����%=�	4�
�
���K� � � rEc��tjt��}||fD�]d}|��t|jd����D]�}|�
|j|vr�	|�|��}	nE#tj$r3}
d�|�	|��D��}|
j
|vr�Yd}
~
�bd}
~
wwxYw|	�'||j�|	|jf����||ur�t|jd����D]�}|�
|j|vr�	|�|��}	nE#tj$r3}
d�|�	|��D��}|
j
|vr�Yd}
~
�bd}
~
wwxYw|	�'||j�|	|jf����|rn��f|S)Nc��|jjSr>��parent�_creation_order��fks r;�<lambda>z0Join._joincond_scan_left_right.<locals>.<lambda>�s��r�y�/H�rE�rc��h|]	}|j��
SrQ�rX�r~r�s  r;�	<setcomp>z1Join._joincond_scan_left_right.<locals>.<setcomp>s��"N�"N�"N�a�1�6�"N�"N�"NrEc��|jjSr>rjrms r;roz0Join._joincond_scan_left_right.<locals>.<lambda>s��b�i�6O�rEc��h|]	}|j��
SrQrrrss  r;rtz1Join._joincond_scan_left_right.<locals>.<setcomp>s��&O�&O�&O�!�q�v�&O�&O�&OrE)
�collections�defaultdictr��sortedr	rk�get_referentr*�NoReferenceError�find_tables�
table_name�
constraint�append)r*�sql_utilr_rPr`rarbr$rnr��nrte�table_namess            r;r[zJoin._joincond_scan_left_right�s��
"�-�d�3�3���q�M�+	�+	�D��|�����$H�$H����
H�
H��-�8��	�)A�A�A��!��/�/�$�/�/�C�C���+�!�!�!�"N�"N�8�3G�3G��3M�3M�"N�"N�"N�K���+�5�5�� ���������!�����?���
�.�5�5�s�B�I�6F�G�G�G���1�}�}� ��%�+O�+O����L�L�B�1�<��I�-E�E�E� �%� �o�o�a�0�0�����/�%�%�%�&O�&O�x�7K�7K�A�7N�7N�&O�&O�&O���?�k�9�9�!�$�H�H�H�H�����%������#�B�M�2�9�9�3��	�:J�K�K�K���
���
��s0�
A � B"�/)B�B"�9D�E�)E�Ec���|rDt|��D]4}td�|jD����t|��kr||=�5t|��dkr]td�|���D����}t|��dkrt|��d}|||i}t|��dkr%tjd|j�d|j�d����dS)Nc3�$K�|]}|jV��dSr>)rk�r~�fs  r;r<z2Join._joincond_trim_constraints.<locals>.<genexpr>*s$����8�8�A�q�x�8�8�8�8�8�8rErc3�4K�|]}t|��V��dSr>)r�)r~rds  r;r<z2Join._joincond_trim_constraints.<locals>.<genexpr>2s(����F�F���t���F�F�F�F�F�FrErzCan't determine join between 'rWz�'; tables have more than one foreign key constraint relationship between them. Please specify the 'onclause' of this join explicitly.)r�r��elementsr�r^r*�AmbiguousForeignKeysErrorr�)r*r_r`rbra�const�dedupers        r;r\zJoin._joincond_trim_constraints!s��$�	+��k�*�*�
+�
+���8�8���8�8�8�8�8�C�,�=�=���$�E�*���{���a����F�F��1C�1C�1E�1E�F�F�F�F�F�F��6�{�{�a����;�'�'��*��"�K��$4�5���{���q� � ��/�/�
'(�m�m�m�Q�]�]�]�	D���
�!� rEc�@�|j|jg}t||fd|gi|��S)aSCreate a :class:`_expression.Select` from this
        :class:`_expression.Join`.

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

            from sqlalchemy import select
            j = select([j.left, j.right], **kw).\
                        where(whereclause).\
                        select_from(j)

        :param whereclause: the WHERE criterion that will be sent to
          the :func:`select()` function

        :param \**kwargs: all other kwargs are sent to the
          underlying :func:`select()` function.

        r�)r$r�ra)rKr�rd�collists    r;rBzJoin.select@s1��(�9�d�j�)���g�{�F�F�d�V�F�v�F�F�FrEc�2�|jjp|jjSr>)r$�bindr�rJs r;r�z	Join.bindXs���y�~�0����0rEc���|r�|�
Jd���|j�d���|j�d���}}|�|���|�|����}|�||�|j��|j|j	���S|�
dd����|��S)a�Return an alias of this :class:`_expression.Join`.

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

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

        The JOIN by itself would look like::

            table_a JOIN table_b ON table_a.id = table_b.a_id

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

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

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

            from sqlalchemy import select, alias
            j = alias(
                select([j.left, j.right]).\
                    select_from(j).\
                    with_labels(True).\
                    correlate(False),
                name=name
            )

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

            j.c.table_a_id
            j.c.table_b_a_id

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

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

        we get a result like this::

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

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

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

        Will produce an expression like::

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

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

        .. versionadded:: 0.9.0 Added the ``flat=True`` option to create
          "aliases" of joins without enclosing inside of a SELECT
          subquery.

        :param name: name given to the alias.

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

         .. versionadded:: 0.9.0

        .. seealso::

            :ref:`core_tutorial_aliases`

            :func:`_expression.alias`

        Nz"Can't send name argument with flatT)r�r)F)�
use_labels�	correlate)r$rbr�r�rErtr�r�r�r�rB)rKr�rXr��left_a�right_a�adapters       r;rbz
Join.alias\s���R�	M��<�<�!E�<�<�<��	���T��*�*��
� � �d� �+�+��F��+�+�F�3�3�9�9��%�%�g�.�.���G��;�;��� � ���/�/����Y�	���
��;�;�$�%�;�@�@�F�F�t�L�L�LrEc�<�tjd�|jD���S)Nc�B�g|]}t|j|j����SrQ)r	r$r��r~rYs  r;r�z$Join._hide_froms.<locals>.<listcomp>�s&��
G�
G�
G��m�A�F�A�G�,�,�
G�
G�
GrE)rDrEr�rJs r;rzJoin._hide_froms�s%����
G�
G�d�6F�
G�
G�
G�
�	
rEc�V�|g|jjz|jjz|jjzSr>)r�r	r$r�rJs r;r	zJoin._from_objects�s7���F��m�)�
*��i�%�
&��j�&�
'�	
rErrr>)FNN) rMrNrOrirjrr'�classmethodr+r-rPr�r�r%r,r rrrrKrNr&�deprecated_paramsrQrgr[r\rBr�rbrr	rQrEr;r�r��s���������$�N��H�����&�C�C�C��[�C�2�=B�39�39�39��[�39�j�
�
��X�
�
�
�
�"�"�"�"��T��,�-�-�

�

�.�-�

����%+�3�3�3�3�4�4�4�F�F�F���T��#
����#(��!%�
<�<�<����[�<�|�
!�
!�
!��[�
!���T��,�-�-�1�1�.�-��[�1�f����[��<G�G�G�G�0�1�1��X�1��T��,�-�-�yM�yM�yM�.�-�yM�v�
�
��X�
�
�
�
��X�
�
�
rEr�c����eZdZdZdZdZdZd�Zed���Z	edd���Z
dd	�Zd�fd
�	Ze
d���Zd�Zd
�Zd�Zd�Zefd�Zdd�Ze
d���Ze
d���Z�xZS)r?a�Represents an table or selectable alias (AS).

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

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

    rbTc	��td|jj�d|jj����d|jj����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.)�NotImplementedErrorr�rM�lower)rK�argrws   r;r'zAlias.__init__�s`��!�!���'�'�'���'�-�-�/�/�/�/���'�-�-�/�/�/�/�
�

�

�
	
rEc�J�|�|��}|j|i|��|Sr>)�__new__�_init)r*r�rw�objs    r;r�zAlias._constructs/���k�k�#������	�3��"�����
rENFc�J�t|���||���S)a	Return an :class:`_expression.Alias` object.

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

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

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

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

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

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

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

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

         .. versionadded:: 0.9.0

        )rXr�)r<rb)r*r4rXr�s    r;�_factoryzAlias._factorys&��b"�*�-�-�3�3��D�3�I�I�IrEc�b�|}t|t��r|j}t|t���||_|j|_|jr|j|_||_|�E|jjrt|jdd��}tdt|��|pdfz��}||_
dS)NrXz
%%(%d %s)s�anon)r2r?r8r@�supports_execution�_execution_optionsrr�rr/rX)rKr4rX�baseselectables    r;r�zAlias._initAs���#�����/�/�	4�+�3�N����/�/�	4�&��
�"0�"C����"�	H�&4�&G�D�#�!����<��}�.�
<��t�}�f�d�;�;��#�L�B�t�H�H�d�n�f�3M�$M�N�N�D���	�	�	rEc���t|t��rBt|jt��r(|j���rt|��St
t|���|���S)N�r5)	r2�CompoundSelectr@ra�_needs_parens_for_groupingr3�superr?r%)rKr5r�s  �r;r%zAlias.self_groupPsr����w��/�/�	&��4�=�&�1�1�	&��
�8�8�:�:�	&�
 ��%�%�%��U�D�!�!�,�,�W�,�=�=�=rEc�^�tjr|jS|j�dd��S�N�ascii�backslashreplace�r,�py3krX�encoderJs r;r�zAlias.descriptionZ�.���9�	A��9���9�#�#�G�-?�@�@�@rEc��	|j���S#t$r6}tjtd|jz��|���Yd}~dSd}~wwxYw)Nz)Element %s does not support 'as_scalar()'r/)r8�	as_scalarr5r,r6)rKr:s  r;r�zAlias.as_scalaras���		��<�)�)�+�+�+���	�	�	��K��$�&*�l�3���!$�
�
�
�
�
�
�
�
�
�
�����	���s��
A�+A�Ac�L�||jvrdS|j�|��S)NT)r�r8r�r�s  r;r�zAlias.is_derived_fromms+����)�)�)��4��|�+�+�J�7�7�7rEc�X�|jjjD]}|�|���dSr>)r8r�r��_make_proxy)rKr�s  r;rz!Alias._populate_column_collectionrs8���<�'�4�	"�	"�C��O�O�D�!�!�!�!�	"�	"rEc�z�|j�|��}|�|jsdS|�|��SdSr>)r8rr
r�rGs   r;rzAlias._refresh_for_new_columnvsC���l�2�2�6�:�:���?��'�
-��t����t�,�,�,��4rEc�
�t|jt��rdS|���||jfi|��|_|j}t|t��r|j}t|t���||_dSr>)r2r8�TableClauserr?r@)rKrJrwr�s    r;rKzAlias._copy_internals�s����d�l�K�0�0�	��F��������u�T�\�0�0�R�0�0���������/�/�	4�+�3�N����/�/�	4�&��
�
�
rEc+�<K�|r|jD]}|V��|jV�dSr>)r�r8)rK�column_collectionsrwr�s    r;rNzAlias.get_children�s>�����	��V�
�
��������l�����rEc��|gSr>rQrJs r;r	zAlias._from_objects��	���v�
rEc��|jjSr>)r8r�rJs r;r�z
Alias.bind�s
���|� � rErr>�T)rMrNrOrirjrrr'r�r�r�r�r%rPr�r�r�rrrrKrNr	r��
__classcell__�r�s@r;r?r?�sz����������N�����
�
�
�����[��
�0J�0J�0J��[�0J�d
�
�
�
�>�>�>�>�>�>��A�A��X�A�
�
�
�8�8�8�
"�"�"����%+�'�'�'�'���������X���!�!��X�!�!�!�!�!rEr?c�2�eZdZdZdZdZedd���ZdS)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.

    .. versionadded:: 1.1

    .. seealso::

        :ref:`lateral_selects` -  overview of usage.

    r�TNc�H�t|���|���S)a�Return a :class:`_expression.Lateral` object.

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

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

        .. versionadded:: 1.1

        .. seealso::

            :ref:`lateral_selects` -  overview of usage.

        rr)r<r�)r*r4rXs   r;r�zLateral._factory�s#��*"�*�-�-�5�5�4�5�@�@�@rEr>)rMrNrOrirjrr�r�rQrEr;r�r��sN��������$�N��K��A�A�A��[�A�A�ArEr�c�r��eZdZdZdZedd���Zd�fd�	Zej	d��d���Z
�xZS)	r�adRepresent a TABLESAMPLE clause.

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

    .. versionadded:: 1.1

    .. seealso::

        :func:`_expression.tablesample`

    r�Nc�L�t|���|||���S)a�Return a :class:`_expression.TableSample` object.

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

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

        e.g.::

            from sqlalchemy import func

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

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

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

        .. versionadded:: 1.1

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

        :param name: optional alias name

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

        )rXr�)r<r�)r*r4r�rXr�s     r;r�zTableSample._factory�s1��X"�*�-�-�9�9��4�d�:�
�
�	
rEc�x��||_||_tt|���||���dS�Nrr)r�r�r�r�r�)rKr4r�rXr�r�s     �r;r�zTableSample._inits:��� ��
���	�
�k�4� � �&�&�z��&�=�=�=�=�=rEr�c��t|j|j��r|jS|j�|j��Sr>)r2r��Functionr��system)rKr�s  r;�_get_methodzTableSample._get_methods9���d�m�Y�%7�8�8�	8��=� ��>�(�(���7�7�7rEr�)rMrNrOrirjr�r�r�r,r r�r�r�s@r;r�r��s��������
�
�#�N��-
�-
�-
��[�-
�^>�>�>�>�>�>�
�T��1�2�2�8�8�3�2�8�8�8�8�8rEr�c���eZdZdZdZed
d���Zddde��ddf�fd�	Ze	f�fd�	Z
ejd��d	���Z
d
d
�Zd�Zd�Z�xZS)�CTEz�Represent a Common Table Expression.

    The :class:`_expression.CTE` object is obtained using the
    :meth:`_expression.SelectBase.cte` method from any selectable.
    See that method for complete examples.

    �cteNFc�J�t|���||���S)z�Return a new :class:`_expression.CTE`,
        or Common Table Expression instance.

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

        �rX�	recursive)r<r�)r*r4rXr�s    r;r�zCTE._factory$s.��"�*�-�-�1�1���2�
�
�	
rEc���||_||_||_|r||_|r||_tt|���||���dSr�)r��
_cte_alias�	_restatesr�r�r�r�r�)	rKr4rXr�r�r�r�r�r�s	        �r;r�z	CTE._init0sa���#���$���"����	'�&�D�N��	'�&�D�N�
�c�4�����z���5�5�5�5�5rEc������tt|��j�fi���|j��|jfi���|_t	��fd�|jD����|_dS)Nc�"��g|]}�|fi�����SrQrQ)r~�elemrJrws  ��r;r�z'CTE._copy_internals.<locals>.<listcomp>Hs+���:�:�:�4�U�U�4�
�
�2�
�
�:�:�:rE)r�r�rKr��	frozensetr�)rKrJrwr�s ``�r;rKzCTE._copy_internalsCs~�����(��c�4���(��5�5�"�5�5�5��?�&�#�e�D�O�:�:�r�:�:�D�O�"�:�:�:�:�:�4�>�:�:�:�
�
����rE�sqlalchemy.sql.dmlc���t|j|j��r&|jjD]}|�|���dS|jjjD]}|�|���dSr>)r2r8�
UpdateBase�
_returningr�r�r�)rK�dmlr�s   r;rzCTE._populate_column_collectionKs����d�l�C�N�3�3�	&��|�.�
&�
&������%�%�%�%�
&�
&��|�+�8�
&�
&������%�%�%�%�
&�
&rEc�j�t�|j||j||j|j���S)a1Return 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:`core_tutorial_aliases`

            :func:`_expression.alias`

        )rXr�r�r�r�)r�r�r@r�r�r�r�s   r;rbz	CTE.aliasTs9���~�~��M���n���n��n�
�
�
�	
rEc���t�|j�|��|j|j|j�|g��|j|j���S�N)rXr�r�r�r�)	r�r�r@�unionrXr�r�r�r�r�s  r;r�z	CTE.unionksY���~�~��M����&�&����n��n�*�*�D�6�2�2��n��n�
�
�
�	
rEc���t�|j�|��|j|j|j�|g��|j|j	���Sr�)
r�r�r@�	union_allrXr�r�r�r�r�r�s  r;r�z
CTE.union_allusY���~�~��M�#�#�E�*�*����n��n�*�*�D�6�2�2��n��n�
�
�
�	
rEr)rMrNrOrirjr�r�r�r�rrKr,r rrbr�r�r�r�s@r;r�r�s����������N��	
�	
�	
��[�	
�����)�+�+���6�6�6�6�6�6�&%+�
�
�
�
�
�
��T��+�,�,�&�&�-�,�&�
�
�
�
�.
�
�
�
�
�
�
�
�
�
rEr�c��eZdZdZdd�ZdS)�HasCTEzTMixin that declares a class to include CTE support.

    .. versionadded:: 1.1

    NFc�<�t�|||���S)aReturn a new :class:`_expression.CTE`,
        or Common Table Expression instance.

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

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

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

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

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

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

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

        The following examples include two from PostgreSQL's documentation at
        http://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)

        .. seealso::

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

        r�)r�r�)rKrXr�s   r;r�z
HasCTE.cte�s��N�~�~�d���~�C�C�CrEr)rMrNrOrir�rQrEr;r�r��s>��������gD�gD�gD�gD�gD�gDrEr�c��eZdZdZdZd�Zd�Zed���Zed���Z	ed���Z
d�Zd	�Zed
���Z
d�Zefd�Zed
���Zd�Zd�Zd�ZdS)r3z%Represent a grouping of a FROM clause�groupingc��||_dSr>rC�rKr8s  r;r'zFromGrouping.__init__6s
������rEc��dSr>rQrJs r;rzFromGrouping._init_collections9����rEc��|jjSr>)r8r�rJs r;r�zFromGrouping.columns<s
���|�#�#rEc��|jjSr>)r8r�rJs r;r�zFromGrouping.primary_key@�
���|�'�'rEc��|jjSr>)r8r	rJs r;r	zFromGrouping.foreign_keysDs
���|�(�(rEc�6�|j�|��Sr>)r8r�r�s  r;r�zFromGrouping.is_derived_fromHs���|�+�+�G�4�4�4rEc�@�t|jjdi|����S)NrQ)r3r8rb)rKrws  r;rbzFromGrouping.aliasKs&���.�D�L�.�4�4��4�4�5�5�5rEc��|jjSr>)r8rrJs r;rzFromGrouping._hide_fromsNr�rEc��|jfSr>rCrMs  r;rNzFromGrouping.get_childrenRs�����rEc�,�||jfi|��|_dSr>rCrIs   r;rKzFromGrouping._copy_internalsUs!���u�T�\�0�0�R�0�0����rEc��|jjSr>)r8r	rJs r;r	zFromGrouping._from_objectsXs
���|�)�)rEc�,�t|j|��Sr>)r�r8)rK�attrs  r;�__getattr__zFromGrouping.__getattr__\s���t�|�T�*�*�*rEc��d|jiS�Nr8rCrJs r;�__getstate__zFromGrouping.__getstate___s���4�<�(�(rEc� �|d|_dSrrC)rK�states  r;�__setstate__zFromGrouping.__setstate__bs���Y�'����rEN)rMrNrOrirjr'rrPr�r�r	r�rbrrNrrKr	rrrrQrEr;r3r31s7������/�/��N����
�
�
��$�$��X�$��(�(��X�(��)�)��X�)�5�5�5�6�6�6��(�(��X�(����%+�1�1�1�1��*�*��X�*�+�+�+�)�)�)�(�(�(�(�(rEr3c���eZdZdZdZdZdZ	dZ	�fd�Zd�Z	e
jd���Zd	�Z
dd
�Ze
jd��dd���Ze
jd��	dd
���Ze
jd��dd���Zed���Z�xZS)r�a-Represents a minimal "table" construct.

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

        from sqlalchemy import table, column

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

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

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

    �tableTFNc���tt|�����|x|_|_t��|_t��|_t��|_
|D]}|�|���|�dd��}|�||_
|r$tjdt!|��z���dS)aProduce a new :class:`_expression.TableClause`.

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

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


        :param name: Name of the table.

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

        :param schema: The schema name for this table.

            .. versionadded:: 1.3.18 :func:`_expression.table` can now
               accept a ``schema`` argument.
        rNrq)r�r�r'rX�fullnamerr�rr�r�r	�
append_columnrsrr*r7r�)rKrXr�rwr�rr�s      �r;r'zTableClause.__init__�s����0	�k�4� � �)�)�+�+�+�$(�(��	�D�M�(�*�*��
�$�;�;����E�E����	"�	"�A����q�!�!�!�!�����$�'�'���� �D�K�
�	N��#�$A�D��H�H�$L�M�M�M�	N�	NrEc��dSr>rQrJs r;rzTableClause._init_collections�r�rEc�^�tjr|jS|j�dd��Sr�r�rJs r;r�zTableClause.description�r�rEc
��|j}|�2||ur.tjd|j�dt	|d|�������||j|j<||_dS)Nzcolumn object 'z' already assigned to table r�)rr*r7rr�r�)rKr��existings   r;rzTableClause.append_column�sl���7����H�D�$8�$8��#�#��5�5�5�'�(�M�8�D�D�D�F���
�
 !��
�a�e������rEc�,�|rd�|jD��SgS)Nc��g|]}|��SrQrQr9s  r;r�z,TableClause.get_children.<locals>.<listcomp>�s��&�&�&�!�A�&�&�&rE)r��rKr�rds   r;rNzTableClause.get_children�s%���	�&�&�t�v�&�&�&�&��IrEr�c�$�|j|f||d�|��S)z�Generate an :func:`_expression.insert` construct against this
        :class:`_expression.TableClause`.

        E.g.::

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

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

        )r^�inline)�Insert)rKr�r^rrds     r;�insertzTableClause.insert�s%���s�z�$�G�v�f�G�G��G�G�GrEc�&�|j|f|||d�|��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.

        )r�r^r)�Update)rKr�r�r^rrds      r;rCzTableClause.update�s:���s�z��
�#���	
�
�
�
�
�	
rEc� �|j||fi|��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.

        )�Delete)rKr�r�rds    r;�deletezTableClause.delete�s ���s�z�$��6�6�v�6�6�6rEc��|gSr>rQrJs r;r	zTableClause._from_objectsr�rEr�r)NNFr>)rMrNrOrirjr�implicit_returning�_autoincrement_columnr'rr,�memoized_propertyr�rrNr rrCrrPr	r�r�s@r;r�r�fsn���������:�N�����=�!��>�$N�$N�$N�$N�$N�L
�
�
�
��A�A���A�	�	�	������T��+�,�,�H�H�H�-�,�H��T��+�,�,�9>�
�
�
�-�,�
�,�T��+�,�,�7�7�7�-�,�7�����X�����rEr�c�b�eZdZed���Zed���Zd�Zd�Ze	fd�Z
					d	d�ZdS)
�ForUpdateArgc��|dvrdSdx}}|dkrd}n/|dkrd}n&|dkrdx}}n|durtjd|z���t||�	��S)
a�Parse the for_update argument of :func:`_expression.select`.

        :param mode: Defines the lockmode to use.

            ``None`` - translates to no lockmode

            ``'update'`` - translates to ``FOR UPDATE``
            (standard SQL, supported by most dialects)

            ``'nowait'`` - translates to ``FOR UPDATE NOWAIT``
            (supported by Oracle, PostgreSQL 8.1 upwards)

            ``'read'`` - translates to ``LOCK IN SHARE MODE`` (for MySQL),
            and ``FOR SHARE`` (for PostgreSQL)

            ``'read_nowait'`` - translates to ``FOR SHARE NOWAIT``
            (supported by PostgreSQL). ``FOR SHARE`` and
            ``FOR SHARE NOWAIT`` (PostgreSQL).

        rNF�nowaitT�read�read_nowaitzUnknown for_update argument: %r�r$r#)r*r7r!)rKr�r#r$s    r;�parse_legacy_selectz ForUpdateArg.parse_legacy_selects���,�-����4������(�?�?��F�F�
�F�]�]��D�D�
�M�
!�
!� � �D�6�6�
��_�_��#�$E��$K�L�L�L���f�5�5�5�5rEc�X�|jr	|jsdS|jr	|jrdS|jrdSdS)Nr$r%r#Tr&rJs r;�legacy_for_update_valuez$ForUpdateArg.legacy_for_update_value1sF���9�	�T�[�	��6�
�Y�	�4�;�	� �=�
�[�	��8��4rEc���t|t��oM|j|jko=|j|jko-|j|jko|j|jko
|j|juSr>)r2r!r#r$�skip_locked�	key_share�ofr�s  r;�__eq__zForUpdateArg.__eq__<sq���u�l�+�+�
$�����+�
$��
�d�i�'�
$��!�T�%5�5�
$���4�>�1�	
$�
��D�G�#�
	
rEc� �t|��Sr>)r/rJs r;�__hash__zForUpdateArg.__hash__Fs
���$�x�x�rEc�N���|j���fd�|jD��|_dSdS)Nc�"��g|]}�|fi�����SrQrQ)r~r�rJrws  ��r;r�z0ForUpdateArg._copy_internals.<locals>.<listcomp>Ks+���;�;�;�C�u�u�S�'�'�B�'�'�;�;�;rE)r-rIs ``r;rKzForUpdateArg._copy_internalsIs8�����7��;�;�;�;�;�4�7�;�;�;�D�G�G�G��rEFNc��||_||_||_||_|�%d�t	j|��D��|_dSd|_dS)z{Represents arguments specified to
        :meth:`_expression.Select.for_update`.

        .. versionadded:: 0.9.0

        Nc�,�g|]}t|����SrQr)r~r�s  r;r�z)ForUpdateArg.__init__.<locals>.<listcomp>as.�����7;�,�T�2�2���rE)r#r$r+r,r,�to_listr-�rKr#r$r-r+r,s      r;r'zForUpdateArg.__init__Msa�������	�&���"���
�>���?C�|�B�?O�?O����D�G�G�G��D�G�G�GrE�FFNFF)rMrNrOr�r'rPr)r.r0rrKr'rQrEr;r!r!s��������"6�"6��[�"6�H����X��
�
�
����%+�<�<�<�<��
����
�����rEr!c��eZdZdZd�Zd�Zeejdd���d�����Z	d�Z
ed	���Zd
S)rAz�Base class for SELECT statements.


    This includes :class:`_expression.Select`,
    :class:`_selectable.CompoundSelect` and
    :class:`.TextAsFrom`.


    c� �t|��S)aLReturn a 'scalar' representation of this selectable, which can be
        used as a column expression.

        Typically, a select statement which has only one column in its columns
        clause is eligible to be used as a scalar expression.

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

        )�ScalarSelectrJs r;r�zSelectBase.as_scalarss���D�!�!�!rEc�P�|����|��S)z�Return a 'scalar' representation of this selectable, embedded as a
        subquery with a label.

        .. seealso::

            :meth:`_expression.SelectBase.as_scalar`.

        )r�r�r�s  r;r�zSelectBase.label�s"���~�~���%�%�d�+�+�+rE�0.6z�The :meth:`.SelectBase.autocommit` method is deprecated, and will be removed in a future release.   Please use the the :paramref:`.Connection.execution_options.autocommit` parameter in conjunction with the :meth:`.Executable.execution_options` method.r�c�H�|j�ddi��|_dS)zQReturn a new selectable with the 'autocommit' flag set to
        True.

        �
autocommitTN)r�r�rJs r;r>zSelectBase.autocommit�s-��#'�"9�"?�"?�
�4� �#
�#
����rEc��|j�|j��}|j���|_|���|S)zWOverride the default _generate() method to also clear out
        exported collections.)r�r�r�copyr)rK�ss  r;�	_generatezSelectBase._generate�sG��
�N�"�"�4�>�2�2���]�'�'�)�)��
�	�������rEc��|gSr>rQrJs r;r	zSelectBase._from_objects�r�rEN)
rMrNrOrir�r�r
r,rr>rBrPr	rQrEr;rArAhs���������"�"�"�	,�	,�	,���T�_�
�8����
�
����[�
��������X���rErAc��eZdZdZe��Ze��ZdZdZdZ									dd�Z
ed���Zej
d���Ze					dd���Zed���Zed	���Zed
���Zed���Zed���Zed
���Zed���Zed���Zed���Zd�Zd�Zed���Zefd�ZdS)�GenerativeSelectaZBase class for SELECT statements where additional elements can be
    added.

    This serves as the base for :class:`_expression.Select` and
    :class:`_selectable.CompoundSelect`
    where elements such as ORDER BY, GROUP BY can be added and column
    rendering can be controlled.  Compare to :class:`.TextAsFrom`, 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.

    .. versionadded:: 0.9.0 :class:`_expression.GenerativeSelect` was added to
       provide functionality specific to :class:`_expression.Select` and
       :class:`_selectable.CompoundSelect` while allowing
       :class:`_expression.SelectBase` to be
       used for other SELECT-like objects, e.g. :class:`.TextAsFrom`.

    NFc	���||_|durt�|��|_|�5t	jd��|j�d|i��|_|�t|��|_	|�t|��|_
||_|�(tt	j
|��dti�|_|�*tt	j
|��dt i�|_dSdS)NFz�The select.autocommit parameter is deprecated and will be removed in a future release.  Please refer to the Select.execution_options.autocommit` parameter.r>r)r�r!r'�_for_update_argr,�warn_deprecatedr�r�rZ�
_limit_clause�_offset_clause�_bindr$r5r�_order_by_clauser�_group_by_clause)	rKr��
for_update�limit�offset�order_by�group_byr�r>s	         r;r'zGenerativeSelect.__init__�s��%����U�"�"�#/�#C�#C�J�#O�#O�D� ��!�� �B�
�
�
�
'+�&=�&C�&C��z�*�'�'�D�#���!8��!?�!?�D����"9�&�"A�"A�D����
���$.���h�'�'�%�!G�%�%�D�!���$.���h�'�'�%�!<�%�%�D�!�!�!� �rEc�,�|j�|jjSdS)z@Provide legacy dialect support for the ``for_update`` attribute.N)rGr)rJs r;rNzGenerativeSelect.for_update�s����+��'�?�?��4rEc�D�t�|��|_dSr>)r!r'rG)rKrYs  r;rNzGenerativeSelect.for_update�s��+�?�?��F�F����rEc�8�t|||||���|_dS)aSpecify a ``FOR UPDATE`` clause for this
        :class:`_expression.GenerativeSelect`.

        E.g.::

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

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

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

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

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

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

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

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

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

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

         .. versionadded:: 1.1.0

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

         .. versionadded:: 1.1.0

        )r#r$r-r+r,N)r!rGr6s      r;�with_for_updatez GenerativeSelect.with_for_update�s1��t ,����#�� 
� 
� 
����rEc��d|_dS)a�Return a new selectable with the 'use_labels' flag set to True.

        This will result in column expressions being generated using labels
        against their table name, such as "SELECT somecolumn AS
        tablename_somecolumn". This allows selectables which contain multiple
        FROM clauses to produce a unique set of column names regardless of
        name conflicts among the individual FROM clauses.

        TN)r�rJs r;�apply_labelszGenerativeSelect.apply_labels?	s������rEc�,�t|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.

        rO)r_rIrJs r;�_limitzGenerativeSelect._limitL	s��-�T�-?��I�I�IrEc�6�t|jt��S)zqTrue if the LIMIT clause is a simple integer, False
        if it is not present or is a SQL expression.
        )r2rIrGrJs r;�_simple_int_limitz"GenerativeSelect._simple_int_limitV	s��
�$�,�.?�@�@�@rEc�6�t|jt��S)zrTrue if the OFFSET clause is a simple integer, False
        if it is not present or is a SQL expression.
        )r2rJrGrJs r;�_simple_int_offsetz#GenerativeSelect._simple_int_offset]	s��
�$�-�/@�A�A�ArEc�,�t|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.

        rP)r_rJrJs r;�_offsetzGenerativeSelect._offsetd	s��-�T�-@�(�K�K�KrEc�.�t|��|_dS)a1Return 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.

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

        :param limit: an integer LIMIT parameter, or a SQL expression
         that provides an integer result.

        N)rZrI)rKrOs  r;rOzGenerativeSelect.limitn	s��$5�U�;�;����rEc�.�t|��|_dS)a8Return a new selectable with the given OFFSET criterion
        applied.


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


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

        :param offset: an integer OFFSET parameter, or a SQL expression
         that provides an integer result.

        N)rZrJ)rKrPs  r;rPzGenerativeSelect.offset�	s��(6�f�=�=����rEc��|j|�dS)a�Return a new selectable with the given list of ORDER BY
        criterion applied.

        e.g.::

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

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

        .. seealso::

            :ref:`core_tutorial_ordering`

        N)�append_order_by�rK�clausess  r;rQzGenerativeSelect.order_by�	s��&	���g�&�&�&�&rEc��|j|�dS)a�Return a new selectable with the given list of GROUP BY
        criterion applied.

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

        N)�append_group_byres  r;rRzGenerativeSelect.group_by�	s��(	���g�&�&�&�&rEc��t|��dkr|d�t��|_dSt|dd���$t	|j��t	|��z}t|dt
i�|_dS)a�Append the given ORDER BY criterion applied to this selectable.

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

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

        .. seealso::

            :meth:`_expression.GenerativeSelect.order_by`

        rrNrLr)r�r$rLr�r�rres  r;rdz GenerativeSelect.append_order_by�	s����w�<�<�1������!3�$.�L�L�D�!�!�!��t�/��6�6�B��t�4�5�5��W�
�
�E��$.��%�!G�%�%�D�!�!�!rEc��t|��dkr|d�t��|_dSt|dd���$t	|j��t	|��z}t|dt
i�|_dS)a�Append the given GROUP BY criterion applied to this selectable.

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

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

        .. seealso::

            :meth:`_expression.GenerativeSelect.group_by`

        rrNrMr)r�r$rMr�r�rres  r;rhz GenerativeSelect.append_group_by�	s����w�<�<�1������!3�$.�L�L�D�!�!�!��t�/��6�6�B��t�4�5�5��W�
�
�E��$.��%�+F�%�%�D�!�!�!rEc��t���r>)r�rJs r;�_label_resolve_dictz$GenerativeSelect._label_resolve_dict�	s��!�#�#�#rEc�r�|j�||jfi|��|_|j�||jfi|��|_dSdSr>)rIrJrIs   r;rKz GenerativeSelect._copy_internals�	s\����)�!&��t�'9�!@�!@�R�!@�!@�D����*�"'�%��(;�"B�"B�r�"B�"B�D����+�*rE)FFNNNNNNr7)rMrNrOrir$rLrMrIrJrGr'rPrN�setterr
rVrXrZr\r^r`rOrPrQrRrdrhrlrrKrQrEr;rErE�s<��������("�z�|�|��!�z�|�|���M��N��O�������
��(�(�(�(�T����X����G�G���G���
����
?
�?
�?
��[�?
�B�
�
��[�
��J�J��X�J��A�A��X�A��B�B��X�B��L�L��X�L��<�<��[�<�&�>�>��[�>�*�'�'��[�'�(�'�'��[�'�*���2���.�$�$��X�$�%+�C�C�C�C�C�CrErEc����eZdZdZdZejd��Zejd��Zejd��Z	ejd��Z
ejd��Zejd��Zd	Z
d
�Zed���Zed���Zed
���Zed���Zed���Zed���Zed���Zd�Zdd�Zd�Zd�Zd�Zef�fd�	Zdd�Zd�Z d�Z!ee e!��Z �xZ"S)r�aXForms 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`

    �compound_select�UNIONz	UNION ALL�EXCEPTz
EXCEPT ALL�	INTERSECTz
INTERSECT ALLTc
�D�|�dd��|_||_g|_d}t	|��D]�\}}t|��}|st
|jj��}ntt
|jj��|krWtj
ddt
|jdjj��|dzt
|jj��fz���|j�|�|�������tj|fi|��dS)Nr�Fz}All selectables passed to CompoundSelect must have identical numbers of columns; select #%d has %d columns, select #%d has %drrr�)rs�_auto_correlate�keyword�selects�	enumeraterr�r�r�r*r7rr%rEr')rKrvrwrd�numcols�nrAs       r;r'zCompoundSelect.__init__
s(��%�z�z�+�u�=�=������������g�&�&�	<�	<�D�A�q�'��*�*�A��
��a�c�.�/�/����Q�S�%�&�&�'�1�1��'�!�
��D�L��O�-�:�;�;��A���A�C�,�-�-�	�		����
�L������T�� :� :�;�;�;�;��!�$�1�1�&�1�1�1�1�1rEc�H�td�|jD����}|||fS)Nc3�(K�|]
}|j|fV��dSr>rpr9s  r;r<z5CompoundSelect._label_resolve_dict.<locals>.<genexpr>?
s(����,�,��!�%���,�,�,�,�,�,rE)�dictr�)rK�ds  r;rlz"CompoundSelect._label_resolve_dict=
s+���,�,�T�V�,�,�,�,�,���!�Q�w�rEc�6�ttjg|�Ri|��S)a�Return a ``UNION`` of multiple selectables.

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

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

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

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

        )r�rq�r*rwrds   r;�
_create_unionzCompoundSelect._create_unionB
s%��$�n�2�G�W�G�G�G��G�G�GrEc�6�ttjg|�Ri|��S)a�Return a ``UNION ALL`` of multiple selectables.

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

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

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

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

        )r��	UNION_ALLr�s   r;�_create_union_allz CompoundSelect._create_union_allV
s%��$�n�6�K��K�K�K�F�K�K�KrEc�6�ttjg|�Ri|��S)a]Return an ``EXCEPT`` of multiple selectables.

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

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

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

        )r�rrr�s   r;�_create_exceptzCompoundSelect._create_exceptj
s%���n�3�H�g�H�H�H��H�H�HrEc�6�ttjg|�Ri|��S)aaReturn an ``EXCEPT ALL`` of multiple selectables.

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

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

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

        )r��
EXCEPT_ALLr�s   r;�_create_except_allz!CompoundSelect._create_except_all{
s%���n�7�L�'�L�L�L�V�L�L�LrEc�6�ttjg|�Ri|��S)a`Return an ``INTERSECT`` of multiple selectables.

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

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

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

        )r�rsr�s   r;�_create_intersectz CompoundSelect._create_intersect�
s%���n�6�K��K�K�K�F�K�K�KrEc�6�ttjg|�Ri|��S)adReturn an ``INTERSECT ALL`` of multiple selectables.

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

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

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

        )r��
INTERSECT_ALLr�s   r;�_create_intersect_allz$CompoundSelect._create_intersect_all�
s%���n�:�O�W�O�O�O��O�O�OrEc�@�|jd���S�Nr)rw�_scalar_typerJs r;r�zCompoundSelect._scalar_type�
s���|�A��+�+�-�-�-rENc� �t|��Sr>r2r4s  r;r%zCompoundSelect.self_group�
r6rEc�J�|jD]}|�|��rdS�dS�NTF)rwr�)rKr�rAs   r;r�zCompoundSelect.is_derived_from�
s:����	�	�A�� � ��,�,�
��t�t�
��urEc��td�|jD���D]f}|d�||jr
|djnd|jr
|djnd���}d�t
|��D��|_�gdS)Nc�&�g|]}|jj��SrQ)r�r�)r~rAs  r;r�z>CompoundSelect._populate_column_collection.<locals>.<listcomp>�
s��A�A�A�q�!�#�*�A�A�ArEr)rXrc�H�g|]\}}|�d|dzi���� Sr�)�	_annotate)r~r�r�s   r;r�z>CompoundSelect._populate_column_collection.<locals>.<listcomp>�
s>�����39�A�q����X�q�1�u�-�.�.���rE)�ziprwr�r�r>�
_key_labelrx�_proxies)rKr��proxys   r;rz*CompoundSelect._populate_column_collection�
s����A�A�D�L�A�A�A�B�	�	�D���G�'�'��'+��@�T�!�W�^�^�D�*.�/�C�D��G�&�&�t�(���E���=F�t�_�_����E�N�N�/	�	rEc�p�|jD]}|�|���|jsdStd���)NzUCompoundSelect constructs don't support addition of columns to underlying selectables)rwrr
r�)rKr�rAs   r;rz&CompoundSelect._refresh_for_new_column�
sQ����	.�	.�A�
�%�%�f�-�-�-�-��#�	��4�!�
�
�
�	
rEc�B����tt|��j�fi���|�����fd�|jD��|_t|d��r|`dD]8}t||���&t||�t||��fi������9dS)Nc�"��g|]}�|fi�����SrQrQ)r~rArJrws  ��r;r�z2CompoundSelect._copy_internals.<locals>.<listcomp>�
s'���=�=�=�1���a���2���=�=�=rE�_col_map)rLrMrG)	r�r�rKrrwrVr�r��setattr)rKrJrwr�r�s `` �r;rKzCompoundSelect._copy_internals�
s������3��n�d�#�#�3�E�@�@�R�@�@�@�������=�=�=�=�=���=�=�=����4��$�$�	��
�
�	F�	F�D�
�t�T�"�"�.���d�E�E�'�$��*=�*=�$D�$D��$D�$D�E�E�E��
	F�	FrEc�z�|rt|j��pg|j|jgzt|j��zSr>)r�r�rLrMrwrs   r;rNzCompoundSelect.get_children�
sA��
�
0�D���L�L�
6�B��$�d�&;�<�
=��4�<� � �
!�	
rEc�P�|jr|jS|jD]}|j}|r|cS�dSr>)rKrwr�)rKrA�es   r;r�zCompoundSelect.bind�
sI���:�	��:����	�	�A���A��
�����
��4rEc��||_dSr>�rK�rKr�s  r;�	_set_bindzCompoundSelect._set_bind�
����
�
�
rEr>r�)#rMrNrOrirjr,�symbolrqr�rrr�rsr�rr'rPrlr�r�r�r�r�r�r�r�r%r�rrrrKrNr�r�r�r�s@r;r�r��	s,���������('�N��D�K�� � �E����K�(�(�I�
�T�[��
"�
"�F����\�*�*�J����K�(�(�I��D�K��0�0�M���2�2�2�>����X���H�H��[�H�&�L�L��[�L�&�I�I��[�I� �M�M��[�M� �L�L��[�L� �P�P��[�P� .�.�.�"�"�"�"�������8
�
�
�%+�F�F�F�F�F�F�
�
�
�
��������8�D�)�$�$�D�D�D�D�DrEr�c�
��eZdZdZdZdZdZej��Z	dZ
dZdZdZ
dZejZdZejdd�	��								d6d
���Zed���Z	d7d�Zd
�Zed���Zd8d�Zed8d���Zed���Zejd���Zed���Zed���Z d�Z!e"f�fd�	Z#d9d�Z$ed���Z%ej&d��d9d���Z'ed���Z(ed���Z)ed���Z*ed���Z+ed ���Z,ed!���Z-ed"���Z.d#�Z/d$�Z0d%�Z1d&�Z2d'�Z3d(�Z4ed)���Z5d*�Z6d+�Z7d,�Z8d:d-�Z9d.�Z:d/�Z;d0�Z<d1�Z=d2�Z>d3�Z?d4�Z@d5�ZAee@eA��Z@�xZBS);raz"Represents a ``SELECT`` statement.rBrQFNT)r<aGThe :paramref:`_expression.select.autocommit` parameter is deprecated and will be removed in a future release.  Please refer to the :paramref:`.Connection.execution_options.autocommit` parameter in conjunction with the the :meth:`.Executable.execution_options` method in order to affect the autocommit behavior for a statement.)rSz�The :paramref:`_expression.select.for_update` parameter is deprecated and will be removed in a future release.  Please refer to the :meth:`_expression.Select.with_for_update` to specify the structure of the ``FOR UPDATE`` clause.)r>rNc	��||_|dur/|durd|_n#d�tj|��D��|_|�6tjd�tj|��D����|_ntj��|_	t
|��}
n?#t$r2}tjtj
d��|���Yd}~nd}~wwxYw|
rkg|_|D]`}t|��}t|t��r |�t j���}|j�|���ang|_|�3t'|���t j���|_nd|_|�3t'|���t j���|_nd|_|r|�|��|r|�|��t3j|fi|	��dS)	a�Construct a new :class:`_expression.Select`.

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

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

        .. seealso::

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

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

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

          .. note::

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

          .. seealso::

            :meth:`_expression.Select.column`

            :meth:`_expression.Select.with_only_columns`

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

          .. seealso::

            :meth:`_expression.Select.where`

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

          .. seealso::

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

        :param autocommit: legacy autocommit parameter.

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

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

          .. seealso::

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

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

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

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

          .. seealso::

            :meth:`_expression.Select.distinct`

        :param for_update=False:
          when ``True``, applies ``FOR UPDATE`` to the end of the
          resulting statement.

          ``for_update`` accepts various string values interpreted by
          specific backends, including:

          * ``"read"`` - on MySQL, translates to ``LOCK IN SHARE MODE``;
            on PostgreSQL, translates to ``FOR SHARE``.
          * ``"nowait"`` - on PostgreSQL and Oracle, translates to
            ``FOR UPDATE NOWAIT``.
          * ``"read_nowait"`` - on PostgreSQL, translates to
            ``FOR SHARE NOWAIT``.

         .. seealso::

            :meth:`_expression.Select.with_for_update` - improved API for
            specifying the ``FOR UPDATE`` clause.

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

          .. seealso::

            :meth:`_expression.Select.group_by`

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

          .. seealso::

            :meth:`_expression.Select.having`

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

          .. seealso::

            :meth:`_expression.Select.limit`

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

          .. seealso::

            :meth:`_expression.Select.offset`

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

          .. seealso::

            :meth:`_expression.Select.order_by`

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

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

          .. seealso::

            :meth:`_expression.Select.apply_labels`

        FTc�,�g|]}t|����SrQr�r~r�s  r;r�z#Select.__init__.<locals>.<listcomp>s0��"�"�"��0��2�2�"�"�"rENc3�4K�|]}t|��V��dSr>�r<r�s  r;r<z"Select.__init__.<locals>.<genexpr>s<����-�-�*+�"�1�%�%�-�-�-�-�-�-rEzDcolumns argument to select() must be a Python list or other iterabler/r�)ru�	_distinctr,r5�
OrderedSet�	_from_objrf�	TypeErrorr6r*r7�_raw_columnsrr2r:r%r�comma_oprr�_asbool�_whereclause�_havingrur�rEr')
rKr�r�r��distinct�havingr�r�r�rd�cols_presentr:r�s
             r;r'zSelect.__init__sx��n )����5� � ��4���!%����"�"�!�\�(�3�3�"�"�"���
��!�_�-�-�/3�|�H�/E�/E�-�-�-���D�N�N�"�_�.�.�D�N�		���=�=�L�L���	�	�	��K��!�9���!$�
�
�
�
�
�
�
�
�
�����	�����	#� "�D���
,�
,��0��3�3���a��.�.�A����Y�-?��@�@�A��!�(�(��+�+�+�+�	
,�!#�D���"� 0�� =� =� H� H�!�)�!I�!�!�D���!%�D����+�F�3�3�>�>�!�)�?���D�L�L� �D�L��	+�� � ��*�*�*��	+�� � ��*�*�*��!�$�1�1�&�1�1�1�1�1s�B�
C�&(C�Cc��g}t��}|j}tjt	|j�|j�t	|j��nd|j��D]q}||urtj	d���|r||vr||}|�
|j��s|�|��|�
|j���r|S)NrQz-select() construct refers to itself as a FROM)r��_from_clonedrDrEr	r�r�r�r*�InvalidRequestErrorr�r�rrC)rK�froms�seen�	translate�items     r;�_fromsz
Select._fromsKs������u�u���%�	��O��4�,�-�� �,�
�$�+�,�,�,���N�
�
�	*�	*�D��t�|�|��-�C�����
'�T�Y�.�.� �����$�$�T�%5�6�6�
#����T�"�"�"��K�K��(�)�)�)�)��rEc���������j�ttjd��D�������rN�jr9���fd����j��D�����fd��D����jr�j��r���fd��D����j����fd��D����j	rJ�rHt���dkr5��fd��D���t���stjd	�z����S)
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.

        c�6�g|]}t|j����SrQ)rrr�s  r;r�z-Select._get_display_froms.<locals>.<listcomp>vs"��K�K�K��n�Q�]�;�;�K�K�KrEc3�r�K�|]1}�j|�|���"�j|V��2dSr>)r�r�)r~r�rKs  �r;r<z,Select._get_display_froms.<locals>.<genexpr>}s[����� � ���(��+�B�B�1�E�E� ��%�a�(� � � � � � rEc���g|]}|�v�|��	SrQrQ)r~r��toremoves  �r;r�z-Select._get_display_froms.<locals>.<listcomp>�s#���;�;�;�1��(�):�):�Q�):�):�):rEc	�X��g|]&}|tt��pd�����v�$|��'S�rQr)r~r��explicit_correlate_fromsr��to_correlates  ���r;r�z-Select._get_display_froms.<locals>.<listcomp>�s`���
�
�
���/�,�!�#;�#A�r���%�	�������rENc	�b��g|]+}|tt��pd���j��v�)|��,Sr�)rr�_correlate_except)r~r�r�r�rKs  ���r;r�z-Select._get_display_froms.<locals>.<listcomp>�sc���
�
�
���)�(��7�=�2����*�	�������rErc�8��g|]}|t����v�|��SrQr)r~r�r��implicit_correlate_fromss  ��r;r�z-Select._get_display_froms.<locals>.<listcomp>�sI��������+�E�3K�L�L�M�M��M�M�MrEz�Select statement '%s' returned no FROM clauses due to auto-correlation; specify correlate(<tables>) to control correlation manually.)
r�r�rDrEr�rCr��
_correlater�rur�r*r�)rKr�r�r�r�r�s```@@@r;�_get_display_fromszSelect._get_display_fromshs��������������O�K�K�U�K�K�K�L�
�
���	<�� �
���� � � � �%�2�2�4�3D�E�E� � � ����<�;�;�;��;�;�;�E��?�
	��?�L��
�
�
�
�
�
�
�"�
�
�
���!�-�
�
�
�
�
�
��
�
�
�E�
� �	�(�	��E�
�
�Q������������E��u�:�:�
��-� �
#'�'�����rEc�^�|jd}t|j��}|djSr�)r�r�r!�type)rKr�r�s   r;r�zSelect._scalar_type�s+��� ��#���D�)�*�*���A�w�|�rEc�*�|���S)z1Return the displayed list of FromClause elements.)r�rJs r;r�zSelect.froms�s���&�&�(�(�(rE�*c�0�|�d||��S)a�Add a statement hint to this :class:`_expression.Select`.

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

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

        .. versionadded:: 1.0.0

        .. seealso::

            :meth:`_expression.Select.with_hint`

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

        N)�	with_hint)rK�text�dialect_names   r;�with_statement_hintzSelect.with_statement_hint�s��.�~�~�d�D�,�7�7�7rEc�z�|�|xj||ffz
c_dS|j�||f|i��|_dS)a�Add an indexing or other executional context hint for the given
        selectable to this :class:`_expression.Select`.

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

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

        Would render SQL as::

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

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

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

        .. seealso::

            :meth:`_expression.Select.with_statement_hint`

        N)�_statement_hints�_hintsr�)rKr4r�r�s    r;r�zSelect.with_hint�sR��F���!�!�|�T�&:�%<�<�!�!�!�!��+�+�+�j�,�-G��,N�O�O�D�K�K�KrEc�*�tjd���)NzvSelect objects don't have a type.  Call as_scalar() on this Select object to return a 'scalar' version of this Select.�r*r�rJs r;r�zSelect.type
s���%�
�
�
�	
rEc�B�|j}|tt|���zS)aReturn a Set of all :class:`_expression.FromClause` elements
        referenced by this Select.

        This set is a superset of that returned by the ``froms`` property,
        which is specifically for those FromClause elements that would
        actually be rendered.

        )r�r�r	)rKr�s  r;�locate_all_fromszSelect.locate_all_froms
s#������t�M�5�1�2�2�2�2rEc�*�t|j��S)z�An iterator of all :class:`_expression.ColumnElement`
        expressions which would
        be rendered into the columns clause of the resulting SELECT statement.

        )r r�rJs r;�
inner_columnszSelect.inner_columns
s��!��!2�3�3�3rEc�@�td�t|j��D����}td�t|j��D����}|���}|���D]\}}|�||���|||fS)Nc3�RK�|]"}|j�	|jp
|jp|j|fV��#dSr>)�_allow_label_resolve�_resolve_labelr>rr9s  r;r<z-Select._label_resolve_dict.<locals>.<genexpr>)
sU����
�
���%�
�
�
�
2���
2�Q�U�A�6�
�
�
�
�
�
rEc3�6K�|]}|j�	|j|fV��dSr>)r�rr9s  r;r<z-Select._label_resolve_dict.<locals>.<genexpr>.
sE����
�
���%�
�
�U�A�J�
�
�
�
�
�
rE)r}r r�r�r@�items�
setdefault)rK�	with_cols�
only_froms�	only_colsrrYs      r;rlzSelect._label_resolve_dict'
s����
�
�&�t�'8�9�9�
�
�
�
�
�	�
�
�
�&�t�z�2�2�
�
�
�
�
�
�
�N�N�$�$�	�$�*�*�,�,�	-�	-�J�C��� � ��e�,�,�,�,��*�i�/�/rEc�z�||jvrdS|���D]}|�|��rdS�dSr�)r�r�r�)rKr�r�s   r;r�zSelect.is_derived_from9
sW���:�)�)�)��4��&�&�(�(�	�	�A�� � ��,�,�
��t�t�
��urEc������tt|��j�fi���t��fd�|j�|j��D����x|_�tj	�fd�|jD����|_t��fd�|jD�����|j��|_|jr>t��fd�|jD�����|j��|_��fd�|j
D��|_
dD]8}t||���&t||�t||��fi������9|���dS)Nc3�.�K�|]}|�|fi���fV��dSr>rQ�r~r�rJrws  ��r;r<z)Select._copy_internals.<locals>.<genexpr>P
sG�����/
�/
�$%�Q���a���2����/
�/
�/
�/
�/
�/
rEc3�(�K�|]}�|V��
dSr>rQ)r~r��from_cloneds  �r;r<z)Select._copy_internals.<locals>.<genexpr>U
s8�����)
�)
� �K��N�)
�)
�)
�)
�)
�)
rEc3�*�K�|]
}�|fi���V��dSr>rQr�s  ��r;r<z)Select._copy_internals.<locals>.<genexpr>_
s1�����F�F��e�e�A�n�n��n�n�F�F�F�F�F�FrEc3�*�K�|]
}�|fi���V��dSr>rQr�s  ��r;r<z)Select._copy_internals.<locals>.<genexpr>f
sB�����)�)�#$���a���2���)�)�)�)�)�)rEc�"��g|]}�|fi�����SrQrQ)r~r�rJrws  ��r;r�z*Select._copy_internals.<locals>.<listcomp>o
s'���G�G�G��U�U�1�^�^��^�^�G�G�GrE)r�r�rLrMrG)r�rarKr}r�r�r�r�r,r�r�r�r�r�r�r�r)rKrJrwr�r�r�s `` @�r;rKzSelect._copy_internalsB
s�������+��f�d���+�E�8�8�R�8�8�8�+/�/
�/
�/
�/
�/
�)-��)=�)=�d�k�)J�)J�/
�/
�/
�+
�+
�	
���K�
��)
�)
�)
�)
�$(�N�)
�)
�)
�
�
����F�F�F�F�F�d�o�F�F�F�F�F�L�L��O�
�
����!�	,�%(�)�)�)�)�)�(,�(>�)�)�)�&�&��e�D�*�+�+�
�"�H�G�G�G�G�T�5F�G�G�G���
�	F�	F�D��t�T�"�"�.���d�E�E�'�$��*=�*=�$D�$D��$D�$D�E�E�E��	
�������rEc��|rt|j��pg|jzt|j��zd�|j|j|j|jfD��zS)z=Return child elements as per the ClauseElement specification.c��g|]}|�|��Sr>rQr�s  r;r�z'Select.get_children.<locals>.<listcomp>�
s)��	�	�	���=��!�=�=rE)r�r�r�r�r�r�rLrMrs   r;rNzSelect.get_children~
sy�� �
6�D���$6�$6�
<�"���
 ��4�;���
 �	�	��%��L��)��)�	�	�	�	�
�	
rEc�0�|�|��dS)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.

        N)rrs  r;r�z
Select.column�
s��	
���6�"�"�"�"�"rEr�c	��|�|j|jg|jft	|j��z�Rd|i���S)aReturn 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.apply_labels`
        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_columnsrBr�r�r�r�)rKr�r�s   r;rBzSelect.reduce_columns�
se��.�%�%�"�G�"��"�
��#�%��d�n�(=�(=�=�
�
�
�+�
�
�
�
�	
rEc��|���g}|D][}t|��}t|t��r |�t
j���}|�|���\||_dS)av
Return a new :func:`_expression.select` construct with its columns
        clause replaced with the given columns.

        This method is exactly equivalent to as if the original
        :func:`_expression.select` had been called with the given columns
        clause.   I.e. 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])

        This means that FROM clauses which are only derived
        from the column list will be discarded if the new column
        list no longer contains that FROM::

            >>> table1 = table('t1', column('a'), column('b'))
            >>> table2 = table('t2', column('a'), column('b'))
            >>> s1 = select([table1.c.a, table2.c.b])
            >>> print(s1)
            SELECT t1.a, t2.b FROM t1, t2
            >>> s2 = s1.with_only_columns([table2.c.b])
            >>> print(s2)
            SELECT t2.b FROM t1

        The preferred way to maintain a specific FROM clause
        in the construct, assuming it won't be represented anywhere
        else (i.e. not in the WHERE clause, etc.) is to set it using
        :meth:`_expression.Select.select_from`::

            >>> s1 = select([table1.c.a, table2.c.b]).\
            ...         select_from(table1.join(table2,
            ...                 table1.c.a==table2.c.a))
            >>> s2 = s1.with_only_columns([table2.c.b])
            >>> print(s2)
            SELECT t2.b FROM t1 JOIN t2 ON t1.a=t2.a

        Care should also be taken to use the correct set of column objects
        passed to :meth:`_expression.Select.with_only_columns`.
        Since the method is
        essentially equivalent to calling the :func:`_expression.select`
        construct in the first place with the given columns, the columns passed
        to :meth:`_expression.Select.with_only_columns`
        should usually be a subset of
        those which were passed to the :func:`_expression.select`
        construct, not those which are available from the ``.c`` collection of
        that :func:`_expression.select`.  That is::

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

        and **not**::

            # usually incorrect
            s = s.with_only_columns([s.c.b])

        The latter would produce the SQL::

            SELECT b
            FROM (SELECT t1.a AS a, t1.b AS b
            FROM t1), t1

        Since the :func:`_expression.select` construct is essentially
        being asked to select both from ``table1`` as well as itself.

        r�N)	rrr2r:r%rr�rr�)rKr��rcr�s    r;r�zSelect.with_only_columns�
s��L	
������
���	�	�A�,�Q�/�/�A��!�\�*�*�
=��L�L��);�L�<�<���I�I�a�L�L�L�L�����rEc�0�|�|��dS)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.

        N)�append_whereclause�rKr�s  r;�wherezSelect.wheres��	
����,�,�,�,�,rEc�0�|�|��dS)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.

        N)�
append_having�rKr�s  r;r�z
Select.havings��	
���6�"�"�"�"�"rEc��|r@d�|D��}t|jt��r|j|z|_dS||_dSd|_dS)aReturn a new :func:`_expression.select` construct which
        will apply DISTINCT to its columns clause.

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

        c�,�g|]}t|����SrQrr�s  r;r�z#Select.distinct.<locals>.<listcomp>.s!��A�A�A�q�/��2�2�A�A�ArETN)r2r�r�)rKrns  r;r�zSelect.distinct#s[���	"�A�A�D�A�A�A�D��$�.�$�/�/�
&�!%��$�!6�����!%�����!�D�N�N�NrEc�0�|�|��dS)a Return a new :func:`_expression.select` construct with the
        given FROM expression(s)
        merged into its list of FROM objects.

        E.g.::

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

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

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

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

        N)�append_fromr�s  r;�select_fromzSelect.select_from6s��F	
����$�$�$�$�$rEc��d|_|r|d�	d|_dSt|j���d�|D����|_dS)aUReturn a new :class:`_expression.Select`
        which will correlate the given FROM
        clauses to that of an enclosing :class:`_expression.Select`.

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

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

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

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

        .. seealso::

            :meth:`_expression.Select.correlate_except`

            :ref:`correlated_subqueries`

        FrNrQc3�4K�|]}t|��V��dSr>r�r�s  r;r<z#Select.correlate.<locals>.<genexpr>�s<����9�9�*+�"�1�%�%�9�9�9�9�9�9rE)rur�r�r��rK�fromclausess  r;r�zSelect.correlate[sj��j %����	�;�q�>�1� �D�O�O�O�!�$�/�2�2�8�8�9�9�/:�9�9�9���D�O�O�OrEc��d|_|r|d�	d|_dSt|jpd���d�|D����|_dS)a�Return a new :class:`_expression.Select`
        which will omit the given FROM
        clauses from the auto-correlation process.

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

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

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

        .. seealso::

            :meth:`_expression.Select.correlate`

            :ref:`correlated_subqueries`

        FrNrQc3�4K�|]}t|��V��dSr>r�r�s  r;r<z*Select.correlate_except.<locals>.<genexpr>�sD����M�M�*+�"�1�%�%�M�M�M�M�M�MrE)rur�r�r�rs  r;�correlate_exceptzSelect.correlate_except�sz��< %����	�;�q�>�1�%'�D�"�"�"�%(��)?�)E�2�%F�%F�%L�%L�M�M�/:�M�M�M�&�&�D�"�"�"rEc��d|_t|j���d�|D����|_dS)aAppend the given correlation expression to this
        :func:`_expression.select` construct.

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

        Fc3�4K�|]}t|��V��dSr>r�r�s  r;r<z,Select.append_correlation.<locals>.<genexpr>�s<����5
�5
�&'��q�!�!�5
�5
�5
�5
�5
�5
rEN)rur�r�r�r�s  r;�append_correlationzSelect.append_correlation�sM�� %����d�o�.�.�4�4�5
�5
�+5�5
�5
�5
�
�
����rEc���|���t|��}t|t��r |�t
j���}|j|gz|_dS)a-Append the given column expression to the columns clause of this
        :func:`_expression.select` construct.

        E.g.::

            my_select.append_column(some_table.c.new_column)

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

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

        r�N)rrr2r:r%rr�r�rs  r;rzSelect.append_column�sg��"	
������-�f�5�5���f�l�+�+�	C��&�&�y�/A�&�B�B�F� �-���8����rEc�D�t|��}|j|fz|_dS)a$Append the given columns clause prefix expression to this
        :func:`_expression.select` construct.

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

        N)rr�)rKr]s  r;�
append_prefixzSelect.append_prefix�s%��"�&�)�)����6�)�3����rEc��|���ttj|j��|��|_dS)afAppend the given expression to this :func:`_expression.select`
        construct's WHERE criterion.

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

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

        N)rr!r'�_ifnoner�rs  r;rzSelect.append_whereclause�s;��	
������ ���t�/@�!A�!A�;�O�O����rEc��|���ttj|j��|��|_dS)aiAppend the given expression to this :func:`_expression.select`
        construct's HAVING criterion.

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

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

        N)rr!r'rr�rs  r;rzSelect.append_havings7��	
�������E�M�$�,�7�7��@�@����rEc��|���t|��}|j�|g��|_dS)a'Append the given FromClause expression to this
        :func:`_expression.select` construct's FROM clause.

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

        N)rr<r�r�r�s  r;rzSelect.append_froms@��	
������'�
�3�3�
���-�-�z�l�;�;����rEc����|jrEt����fd���fd�tjt	|j����D��Sd�tjt	|j����D��S)Nc���|j�|jsd|fS|j}|�vr|j}n��|��||fSr>)r>�_render_label_in_columns_clause�
anon_labelr�)r�rX�namess  �r;�name_for_colz0Select._columns_plus_names.<locals>.name_for_col!sN����8�#�1�+L�#� �!�9�$��x���5�=�=��<�D�D��I�I�d�O�O�O��Q�w�rEc�&��g|]
}�|����SrQrQ)r~r�r#s  �r;r�z.Select._columns_plus_names.<locals>.<listcomp>,s1���������Q�����rEc��g|]}d|f��Sr>rQr9s  r;r�z.Select._columns_plus_names.<locals>.<listcomp>1s,�������q�	���rE)r�r�r,�unique_listr r�)rKr#r"s @@r;�_columns_plus_nameszSelect._columns_plus_namess������?�	��E�E�E�	
�	
�	
�	
�	
������)�*;�D�<M�*N�*N�O�O����
�
���)�*;�D�<M�*N�*N�O�O����
rEc���|jD]W\}}t|d��s�|�d}n#|jr|j}|�||jvr|j}nd}|�|||d����XdS)Nr�T)rrX�name_is_truncatable)r'rVr�r�r�r!r�)rKrXr�rs    r;rz"Select._populate_column_collection6s����/�	N�	N�G�D�!��1�m�,�,�
���|������
��l���?�s�d�f�}�}��,�C����
�M�M�$�C�d��M�M�M�M�M�	N�	NrEc��|jD]�}|�|��}|�h||jvr\|jrU|jr|jn|j}||jvr7|�||jr|j	nd|jr|jndd���cSdS��dS)NT)rXrr))
r�rr�r
r�r�rr�r�r>)rKr�r�r��	our_labels     r;rzSelect._refresh_for_new_columnDs����+�	�	�J��4�4�V�<�<�C����$�,�,�,��1E�,�26�/� N����s�w�I� ���.�.�"��� �/3��!H����D�26�/� K����t�04�	 /� � �����t�t���trEc�X�|jdup!|jdupt|jj��Sr>)rIrJrfrLrfrJs r;r�z!Select._needs_parens_for_groupingTs8����d�*�
3��"�$�.�
3��D�)�1�2�2�	
rEc�v�t|t��r|���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.

        )r2r�r�r3r4s  r;r%zSelect.self_group[s?��
�w��/�/�	��3�3�5�5�	��K��D�!�!�!rEc�(�tj||fi|��S)zaReturn a SQL ``UNION`` of this select() construct against
        the given selectable.

        )r�r��rKr�rds   r;r�zSelect.unionks��
�+�D�%�B�B�6�B�B�BrEc�(�tj||fi|��S)zeReturn a SQL ``UNION ALL`` of this select() construct against
        the given selectable.

        )r�r�r/s   r;r�zSelect.union_allr���
�/��e�F�F�v�F�F�FrEc�(�tj||fi|��S)zbReturn a SQL ``EXCEPT`` of this select() construct against
        the given selectable.

        )r�r�r/s   r;�except_zSelect.except_ys��
�,�T�5�C�C�F�C�C�CrEc�(�tj||fi|��S)zfReturn a SQL ``EXCEPT ALL`` of this select() construct against
        the given selectable.

        )r�r�r/s   r;�
except_allzSelect.except_all�s��
�0��u�G�G��G�G�GrEc�(�tj||fi|��S)zeReturn a SQL ``INTERSECT`` of this select() construct against
        the given selectable.

        )r�r�r/s   r;r�zSelect.intersect�r1rEc�(�tj||fi|��S)ziReturn a SQL ``INTERSECT ALL`` of this select() construct
        against the given selectable.

        )r�r�r/s   r;�
intersect_allzSelect.intersect_all�s��
�3�D�%�J�J�6�J�J�JrEc��|jr|jS|j}|s|jD]}|j}|r||_|cS�n%t	|��dj}|r	||_|SdSr�)rKr�r�r�r�)rKr�r�r�s    r;r�zSelect.bind�s����:�	��:������
	��&�
�
���F����!"�D�J��H�H�H��
��U���A��#�A��
���
����trEc��||_dSr>r�r�s  r;r�zSelect._set_bind�r�rE)NNNFNTNNr�)r�r�r>)CrMrNrOrirjr�r�r,�
immutabledictr�r�r�r�r�r�rAr�rr�r'rPr�r�r�r�r�r
r�r��methodr�r�rlr�rrKrNr�r rBr�rr�r�rr�rrrrrrrr'rrr�r%r�r�r3r5r�r8r�r�r�r�s@r;raras��������,�,��N��I��I�
�T�
�
!�
!�F����I��L��J���#�6���J��T��	
�
����,��������]2�]2�]2�)��(]2�~����X��:GK�R�R�R�R�h���
�)�)��X�)�
8�8�8�8�2�%P�%P�%P��[�%P�N�
�
��X�
���
3�
3���
3��4�4��X�4��0�0���0�"���%+�:�:�:�:�:�:�x
�
�
�
�&�#�#��[�#� �T��,�-�-�
�
�
�.�-�
�<�L�L��[�L�\�-�-��[�-��#�#��[�#��"�"��[�"�$�"%�"%��[�"%�H�:�:��[�:�x�#�#��[�#�J

�

�

�9�9�9�2
4�
4�
4�
P�
P�
P�A�A�A�<�<�<�������2N�N�N���� 
�
�
�"�"�"�"� C�C�C�G�G�G�D�D�D�H�H�H�G�G�G�K�K�K����$����8�D�)�$�$�D�D�D�D�DrErac�V�eZdZgZdZdZd�Zed���ZeZ	e
d���Zd�ZdS)r:TFc�F�||_|���|_dSr>)r8r�r�r�s  r;r'zScalarSelect.__init__�s ������(�(�*�*��	�	�	rEc�*�tjd���)NzcScalar Select expression has no columns; use this object directly within a column-level expression.r�rJs r;r�zScalarSelect.columns�s���%�
0�
�
�	
rEc�D�|j�|��|_dS)zuApply a WHERE clause to the SELECT statement referred to
        by this :class:`_expression.ScalarSelect`.

        N)r8r)rKrds  r;rzScalarSelect.where�s���|�)�)�$�/�/����rEc��|Sr>rQrMs  r;r%zScalarSelect.self_group�s���rEN)
rMrNrOr	r�_is_implicitly_booleanr'rPr�r�r
rr%rQrEr;r:r:�s~�������M���"��+�+�+��
�
��X�
�	�A��0�0��[�0�����rEr:c�J�eZdZdZejZgZd�Zd	d�Zd�Z	d�Z
d�Zd�ZdS)
�ExistszRepresent an ``EXISTS`` clause.c�@�|r+t|dttf��r	|d}nC|std��gf}t	|i|��������}tj||tj
tjd���dS)a\Construct a new :class:`_expression.Exists` against an existing
        :class:`_expression.Select` object.

        Calling styles are of the following forms::

            # use on an existing select()
            s = select([table.c.col1]).where(table.c.col2==5)
            s_e = exists(s)

            # an exists is usually used in a where of another select
            # to produce a WHERE EXISTS (SELECT ... )
            select([table.c.col1]).where(s_e)

            # but can also be used in a select to produce a
            # SELECT EXISTS (SELECT ... ) query
            select([s_e])

            # construct a select() at once
            exists(['*'], **select_arguments).where(criterion)

            # columns argument is optional, generates "EXISTS (SELECT *)"
            # by default.
            exists().where(table.c.col2==5)

        rr�T)r�rT�wraps_column_expressionN)
r2rAr:r&rar�r%r(r'r�existsr�BOOLEANTYPE)rKrcrdrAs    r;r'zExists.__init__�s���4�	A�J�t�A�w��\�(B�C�C�	A��Q��A�A��
0�'��,�,�-�/����'��'�'�1�1�3�3�>�>�@�@�A�� ��
��%��&�$(�	
�	
�	
�	
�	
�	
rENc� �t|g|fi|��Sr>r�r�s   r;rBz
Exists.select�s���t�f�k�4�4�V�4�4�4rEc�z�|���}|jj|����|_|Sr>)rr8r�r%�rKr�r�s   r;r�zExists.correlate�s3���K�K�M�M��*�D�L�*�J�7�B�B�D�D��	��rEc�z�|���}|jj|����|_|Sr>)rr8rr%rKs   r;rzExists.correlate_excepts3���K�K�M�M��1�D�L�1�:�>�I�I�K�K��	��rEc��|���}|j�|�����|_|S)z�Return a new :class:`_expression.Exists` construct,
        applying the given
        expression to the :meth:`_expression.Select.select_from`
        method of the select
        statement contained.

        )rr8rr%�rKr]r�s   r;rzExists.select_froms9��
�K�K�M�M���L�,�,�V�4�4�?�?�A�A��	��rEc��|���}|j�|�����|_|S)z�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.

        )rr8rr%rNs   r;rzExists.wheres9��
�K�K�M�M���L�&�&�v�.�.�9�9�;�;��	��rEr>)
rMrNrOrir(rjr	r'rBr�rrrrQrEr;rDrD�s�������)�)�$�3�N��M�'
�'
�'
�R5�5�5�5����
���

�
�
�����rErDc�d�eZdZdZdZdZdd�Zed���Ze	d���Z
d�Zefd	�Z
d
�ZdS)
�
TextAsFromadWrap 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:`.TextAsFrom` construct is produced via the
    :meth:`_expression.TextClause.columns`
    method - see that method for details.

    .. versionadded:: 0.9.0

    .. seealso::

        :func:`_expression.text`

        :meth:`_expression.TextClause.columns`

    �text_as_fromTFc�0�||_||_||_dSr>)r8�column_args�
positional)rKr�r�rUs    r;r'zTextAsFrom.__init__<s�����"���$����rEc��|jjSr>)r8rKrJs r;rKzTextAsFrom._bindAs
���|�!�!rEc�4�|jj|i|��|_dSr>)r8�
bindparams)rK�binds�bind_as_valuess   r;rXzTextAsFrom.bindparamsEs!��.�t�|�.��H��H�H����rEc�D�|jD]}|�|���dSr>)rTr�)rKr�s  r;rz&TextAsFrom._populate_column_collectionIs3���!�	 �	 �A�
�M�M�$�����	 �	 rEc�T�|���||jfi|��|_dSr>)rr8rIs   r;rKzTextAsFrom._copy_internalsMs3���������u�T�\�0�0�R�0�0����rEc�&�|jdjSr�)rTr�rJs r;r�zTextAsFrom._scalar_typeQs�����"�'�'rENr)rMrNrOrirjrr'rPrKr
rXrrrKr�rQrEr;rQrQs���������0$�N��H�%�%�%�%�
�"�"��X�"��I�I��[�I� � � �%+�1�1�1�1�(�(�(�(�(rErQc��eZdZd�ZdS)�AnnotatedFromClausec�@�|jtj|||��dSr>)r�rr')rKr8r^s   r;r'zAnnotatedFromClause.__init__Vs&��	�	�	���4��&�1�1�1�1�1rEN)rMrNrOr'rQrEr;r_r_Us#������2�2�2�2�2rEr_r�)IrirwrDr�r�sqlalchemy.sql.visitorsrrVrr�
annotationr�baser	r
rrr
rrr�rrrrrrrrrrrrr r!r"r#r$r%r&r'r(r*r+r,r<rDrGrZr_rerg�objectrmr�r�r�r?r�r�r�r�r3r�r!rArEr�rar:rDrQr_rQrEr;�<module>resZ����������������������-�-�-�-�-�-�������������!�!�!�!�!�!�������������"�"�"�"�"�"�������������������������&�&�&�&�&�&�-�-�-�-�-�-�������(�(�(�(�(�(�*�*�*�*�*�*�-�-�-�-�-�-�$�$�$�$�$�$�2�2�2�2�2�2�<�<�<�<�<�<�1�1�1�1�1�1�&�&�&�&�&�&�'�'�'�'�'�'�'�'�'�'�'�'�������#�#�#�#�#�#�#�#�#�#�#�#� � � � � � �������$�$�$�$�$�$�������%�%�%�%�%�%�������������������

�

�

����$�$�$�$�$�
�$�$�$�H�H�H�H�$!�!�!�0
0�
0�
0�	�	�	�	�	��	�	�	�1
�1
�1
�1
�1
�&�1
�1
�1
�h,
�,
�,
�,
�,
�&�,
�,
�,
�^]�]�]�]�]��]�]�]�@K
�K
�K
�K
�K
�:�K
�K
�K
�\q!�q!�q!�q!�q!�J�q!�q!�q!�h+A�+A�+A�+A�+A�e�+A�+A�+A�\L8�L8�L8�L8�L8�%�L8�L8�L8�^d
�d
�d
�d
�d
�*�k�;��d
�d
�d
�NnD�nD�nD�nD�nD�V�nD�nD�nD�b2(�2(�2(�2(�2(�:�2(�2(�2(�jb�b�b�b�b�)�Z�b�b�b�JZ�Z�Z�Z�Z�=�Z�Z�Z�zA�A�A�A�A���Z�A�A�A�HOC�OC�OC�OC�OC�z�OC�OC�OC�d
G%�G%�G%�G%�G%�%�G%�G%�G%�Tb%�b%�b%�b%�b%�[�+�'7�b%�b%�b%�J%�����:�x����>P�P�P�P�P�_�P�P�P�f3(�3(�3(�3(�3(��3(�3(�3(�l2�2�2�2�2�)�2�2�2�2�2rE

Hacked By AnonymousFox1.0, Coded By AnonymousFox