Files
Home-AssistantConfig/deps/sqlalchemy/sql/__pycache__/selectable.cpython-34.pyc

1836 lines
116 KiB
Plaintext
Raw Normal View History

2016-10-11 16:42:06 +00:00
<EFBFBD>
|<7C><>W<15><00>@sydZddlmZmZmZmZmZmZmZm Z ddlm
Z
m Z m Z m Z mZmZmZmZmZmZmZmZddlmZmZmZmZmZmZmZddlmZddlm Z ddlm!Z!dd lm"Z"d
d l#m$Z$dd lm%Z%d
d l#Z#d
d l&Z&ddl'm(Z(d
d l)Z)d
dl*m+Z+dd<00>Z,dd<00>Z-Gdd<00>de <00>Z.d d dd<00>Z/dd<00>Z0dd<00>Z1d ddd<00>Z2Gdd <00>d e<00>Z3Gd!d"<00>d"e4<00>Z5Gd#d$<00>d$e4<00>Z6Gd%d&<00>d&e3<00>Z7Gd'd(<00>d(e7<00>Z8Gd)d*<00>d*e7<00>Z9Gd+d,<00>d,ee6e9<00>Z:Gd-d.<00>d.e7<00>Z;Gd/d0<00>d0ee7<00>Z<Gd1d2<00>d2e<00>Z=Gd3d4<00>d4ee7<00>Z>Gd5d6<00>d6e><00>Z?Gd7d8<00>d8e?<00>Z@Gd9d:<00>d:e5e6e?<00>ZAGd;d<<00>d<ee<00>ZBGd=d><00>d>e<00>ZCGd?d@<00>d@e><00>ZDGdAdB<00>dBe(<00>ZEd S)CziThe :class:`.FromClause` class of SQL expression elements, representing
SQL tables and derived rowsets.
<EFBFBD>)<08> ClauseElement<6E>
TextClause<EFBFBD>
ClauseList<EFBFBD>and_<64>Grouping<6E>UnaryExpression<6F>literal_column<6D> BindParameter) <0C>_clone<6E>_literal_as_text<78>_interpret_as_column_or_from<6F>_expand_cloned<65>_select_iterables<65>_anonymous_label<65>_clause_element_as_expr<70>_cloned_intersection<6F>_cloned_difference<63>True_<65>_literal_as_label_reference<63>&_literal_and_labels_as_label_reference)<07> Immutable<6C>
Executable<EFBFBD> _generative<76>ColumnCollection<6F> ColumnSet<65> _from_objects<74>
Generative)<01>type_api<70>)<01>
inspection)<01>util)<01>exc<78>)<01>
attrgetter)<01> operatorsN)<01> Annotated)<01> Visitablec Cs<>tj|dd<00>}|dkrit|tj<00>ritjditj|<00>d6<>ttj|<00><00>Sny |j SWn!t
k
r<>t j d<00><00>YnXdS)NZraiseerrFz<46>Textual SQL FROM expression %(expr)r should be explicitly declared as text(%(expr)r), or use table(%(expr)r) for more specificity<74>exprzFROM expression expected) r<00>inspect<63>
isinstancer <00> string_typesZ warn_limitedZellipses_stringr<00> text_type<70>
selectable<EFBFBD>AttributeErrorr!<00> ArgumentError)<02>elementZinsp<73>r0<00>?/tmp/pip-build-zkr322cu/sqlalchemy/sqlalchemy/sql/selectable.py<70>_interpret_as_from#s   r2cCsIt|<00>}t|t<00>r'|j}nt|t<00>sE|j<00>}n|S)N)r2r)<00>Alias<61>original<61>
SelectBase<EFBFBD>select)r/r0r0r1<00>_interpret_as_select4s   r7c@s"eZdZedd<00><00>ZdS)<04>_OffsetLimitParamcCs|jS)N)Zeffective_value)<01>selfr0r0r1<00>_limit_offset_value>sz%_OffsetLimitParam._limit_offset_valueN)<05>__name__<5F>
__module__<EFBFBD> __qualname__<5F>propertyr:r0r0r0r1r8=s r8cCsh|dkrdSt|d<00>r)|j<00>St|t<00>r<|Stj|<00>}t||d|dd<00>SdS)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__<5F>type_<65>uniqueT)<07>hasattrr?r)r&r <00>asintr8)r/<00>namer@<00>valuer0r0r1<00>_offset_or_limit_clauseCs 
rFc CsV|dkrdSy |j}Wn%tk
rDtjd|<16><00>YnXtj|<00>SdS)z<>Convert the "offset or limit" clause of a select construct to an
integer.
This is only possible if the value is stored as a simple bound parameter.
Otherwise, a compilation error is raised.
Nz@This SELECT structure does not use a simple integer value for %s)r:r-r!<00> CompileErrorr rC)<03>clause<73>attrnamerEr0r0r1<00>_offset_or_limit_clause_asintUs   rJcOst||<00>j|<00>S)z<>Return an :class:`.Alias` object derived
from a :class:`.Select`.
name
alias name
\*args, \**kwargs
all other arguments are delivered to the
:func:`select` function.
)<02>Select<63>alias)rL<00>args<67>kwargsr0r0r1<00>subqueryis rOFcCs|jd|d|<00>S)a<>Return an :class:`.Alias` object.
An :class:`.Alias` represents any :class:`.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:`~.FromClause.alias` method
available on all :class:`.FromClause` subclasses.
When an :class:`.Alias` is created from a :class:`.Table` object,
this has the effect of the table being rendered
as ``tablename AS aliasname`` in a SELECT statement.
For :func:`.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:`.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:`.Join` - see :meth:`.Join.alias`
for details.
.. versionadded:: 0.9.0
rD<00>flat)rL)r,rDrPr0r0r1rLys(rLc@s4eZdZdZdZdZedd<00><00>ZdS)<07>
Selectablez mark a class as being selectabler,TcCs|S)Nr0)r9r0r0r1r,<00>szSelectable.selectableN)r;r<r=<00>__doc__<5F>__visit_name__Z is_selectabler>r,r0r0r0r1rQ<00>s rQc@s7eZdZfZedd<00><00>Zddd<00>ZdS)<06> HasPrefixescOsK|jdd<00>}|r7tjddj|<00><16><00>n|j||<00>dS)aAdd 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")
Multiple prefixes can be specified by multiple calls
to :meth:`.prefix_with`.
:param \*expr: textual or :class:`.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.
<20>dialectNzUnsupported argument(s): %s<>,)<05>popr!r.<00>join<69>_setup_prefixes)r9r'<00>kwrUr0r0r1<00> prefix_with<74>s
 zHasPrefixes.prefix_withNcs-|jt<00>fdd<00>|D<><00>|_dS)Ncs(g|]}t|dd<00><01>f<00>qS)<02>warnF)r )<02>.0<EFBFBD>p)rUr0r1<00>
<listcomp><3E>s z/HasPrefixes._setup_prefixes.<locals>.<listcomp>)<02> _prefixes<65>tuple)r9<00>prefixesrUr0)rUr1rY<00>s zHasPrefixes._setup_prefixes)r;r<r=r`rr[rYr0r0r0r1rT<00>s rTc@s7eZdZfZedd<00><00>Zddd<00>ZdS)<06> HasSuffixescOsK|jdd<00>}|r7tjddj|<00><16><00>n|j||<00>dS)a<>Add one or more expressions following the statement as a whole.
This is used to support backend-specific suffix keywords on
certain constructs.
E.g.::
stmt = select([col1, col2]).cte().suffix_with(
"cycle empno set y_cycle to 1 default 0", dialect="oracle")
Multiple suffixes can be specified by multiple calls
to :meth:`.suffix_with`.
:param \*expr: textual or :class:`.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.
rUNzUnsupported argument(s): %srV)rWr!r.rX<00>_setup_suffixes)r9r'rZrUr0r0r1<00> suffix_with<74>s
 zHasSuffixes.suffix_withNcs-|jt<00>fdd<00>|D<><00>|_dS)Ncs(g|]}t|dd<00><01>f<00>qS)r\F)r )r]r^)rUr0r1r_<00>s z/HasSuffixes._setup_suffixes.<locals>.<listcomp>)<02> _suffixesra)r9<00>suffixesrUr0)rUr1rd<00>s zHasSuffixes._setup_suffixes)r;r<r=rfrrerdr0r0r0r1rc<00>s rcc@s<>eZdZdZdZdZgZdZdZdZ dZ
dZ e j dg<00>Ze jddd<00>e jd <00>dd
d <00><00><00>Zdd d <00>Zdddd<00>Zddd<00>Zdddd<00>Zdd<00>Zdd<00>Ze jd<00>dd<00><00>Zdd<00>Zddd<00>Zedd <00><00>Zd!d"<00>Zed#d$<00><00>Zed%d&<00><00>Zed'd(<00><00>Z ee!d)<00>d*d+<00>Z"ee!d)<00><00>Z#d,d-<00>Z$ed.d/<00><00>Z%d0d1<00>Z&d2d3<00>Z'dS)4<>
FromClausea<EFBFBD>Represent an element that can be used within the ``FROM``
clause of a ``SELECT`` statement.
The most common forms of :class:`.FromClause` are the
:class:`.Table` and the :func:`.select` constructs. Key
features common to all :class:`.FromClause` objects include:
* a :attr:`.c` collection, which provides per-name access to a collection
of :class:`.ColumnElement` objects.
* a :attr:`.primary_key` attribute, which is a collection of all those
:class:`.ColumnElement` objects that indicate the ``primary_key`` flag.
* Methods to generate various derivations of a "from" clause, including
:meth:`.FromClause.alias`, :meth:`.FromClause.join`,
:meth:`.FromClause.select`.
<20>
fromclauseFN<EFBFBD>_columnsz1.1<EFBFBD>messagea``Table.count()`` is deprecated. Counting rows requires that the correct column expression and accommodations for joins, DISTINCT, etc. must be made, otherwise results may not be what's expected. Please use an appropriate ``func.count()`` expression directly.zsqlalchemy.sql.functionscKsc|jrt|j<00>d}nt|j<00>d}t|jj|<00>jd<00>g|d|g|<00>S)a<>return a SELECT COUNT generated against this
:class:`.FromClause`.
The function generates COUNT against the
first column in the primary key of the table, or against
the first column in the table overall. Explicit use of
``func.count()`` should be preferred::
row_count = conn.scalar(
select([func.count('*')]).select_from(table)
)
.. seealso::
:data:`.func`
r"Z tbl_row_count<6E>from_obj)<07> primary_key<65>list<73>columnsrK<00>func<6E>count<6E>label)r9Z functions<6E> whereclause<73>params<6D>colr0r0r1rq!s zFromClause.countcKst|g||<00>S)z<>return a SELECT of this :class:`.FromClause`.
.. seealso::
:func:`~.sql.expression.select` - general purpose
method which allows for arbitrary column lists.
)rK)r9rsrtr0r0r1r6Is
zFromClause.selectcCst||||<00>S)asReturn a :class:`.Join` from this :class:`.FromClause`
to another :class:`FromClause`.
E.g.::
from sqlalchemy import join
j = user_table.join(address_table,
user_table.c.id == address_table.c.user_id)
stmt = select([user_table]).select_from(j)
would emit SQL along the lines of::
SELECT user.id, user.name FROM user
JOIN address ON user.id = address.user_id
:param right: the right side of the join; this is any
:class:`.FromClause` object such as a :class:`.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:`.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.
.. seealso::
:func:`.join` - standalone function
:class:`.Join` - the type of object produced
)<01>Join)r9<00>right<68>onclause<73>isouterr0r0r1rXUs$zFromClause.joincCst|||d<00>S)a*Return a :class:`.Join` from this :class:`.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:`.FromClause` object such as a :class:`.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:`.FromClause.join` will attempt to
join the two tables based on a foreign key relationship.
.. seealso::
:meth:`.FromClause.join`
:class:`.Join`
T)rv)r9rwrxr0r0r1<00> outerjoin{s$zFromClause.outerjoincCs t||<00>S)z<>return an alias of this :class:`.FromClause`.
This is shorthand for calling::
from sqlalchemy import alias
a = alias(self, name=name)
See :func:`~.expression.alias` for details.
)r3)r9rDrPr0r0r1rL<00>s zFromClause.aliascCs ||jkS)z<>Return True if this FromClause is 'derived' from the given
FromClause.
An example would be an Alias of a Table is derived from that Table.
)<01> _cloned_set)r9rir0r0r1<00>is_derived_from<6F>s
zFromClause.is_derived_fromcCs|jj|j<00>S)z<>Return True if this 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{<00> intersection)r9<00>otherr0r0r1<00>_is_lexical_equivalent<6E>sz!FromClause._is_lexical_equivalentzsqlalchemy.sql.utilcCs|j|<00>j|<00>S)z<>replace all occurrences of FromClause 'old' with the given Alias
object, returning a copy of this :class:`.FromClause`.
)<02> ClauseAdapter<65>traverse)r9<00>sqlutil<69>oldrLr0r0r1<00>replace_selectable<6C>szFromClause.replace_selectablecCsh|j|dd<00>}|dkrd||krdx4||D]%}|j|dd<00>}|r8|Sq8Wn|S)zzReturn corresponding_column for the given column, or if None
search for a match in the given dictionary.
<20>require_embeddedTN)<01>corresponding_column)r9<00>columnZ equivalentsru<00>equivZncr0r0r1<00>correspond_on_equivalents<74>s z$FromClause.correspond_on_equivalentsc s`dd<00>}|jj<00><00>r"<00>Sd\}}<00>j}|jj}x|D]}tt|j<00><00>} |j| <00>}
|
rJ| s<>|| |<00>rJ|dkr<>||
}}qXt|
<00>t|<00>kr<>||
}}qX|
|krXtj t
j <00>fdd<00>|jD<><00>} tj t
j <00>fdd<00>|jD<><00>} | | krU||
}}qUqXqJqJW|S)a<>Given a :class:`.ColumnElement`, return the exported
:class:`.ColumnElement` object from this :class:`.Selectable`
which corresponds to that original
:class:`~sqlalchemy.schema.Column` via a common ancestor
column.
:param column: the target :class:`.ColumnElement` to be matched
:param require_embedded: only return corresponding columns for
the given :class:`.ColumnElement`, if the given
:class:`.ColumnElement` is actually present within a sub-element
of this :class:`.FromClause`. Normally the column will match if
it merely shares a common ancestor with one of the exported
columns of this :class:`.FromClause`.
cSs@x9|j|<00>D](}tt|g<00><00>j|<00>sdSqWdS)NFT)<04>
difference<EFBFBD>setr r})<03>expanded_proxy_set<65>
target_set<EFBFBD>tr0r0r1<00>embedded<65>sz1FromClause.corresponding_column.<locals>.embeddedNcs4g|]*}|j<00><00>r|jjdd<00><00>qS)<02>weightr)<03>shares_lineage<67> _annotations<6E>get)r]<00>sc)r<>r0r1r_s z3FromClause.corresponding_column.<locals>.<listcomp>cs4g|]*}|j<00><00>r|jjdd<00><00>qS)r<>r)r<>r<>r<>)r]r<>)r<>r0r1r_s )NN) <0C>cZcontains_columnZ proxy_set<65> _all_columnsr<73>r r}<00>lenr <00>reduce<63>operator<6F>add) r9r<>r<>r<>ru<00> intersectr<74><00>colsr<73>r<><00>iZ col_distanceZ
c_distancer0)r<>r1r<><00>s6         zFromClause.corresponding_columncCst|d|jjd<17>S)zga brief description of this FromClause.
Used primarily for error message formatting.
rDz object)<03>getattr<74> __class__r;)r9r0r0r1<00> description$szFromClause.descriptioncCs|jj|<00>dS)z8delete memoized collections when a FromClause is cloned.N)<02>_memoized_propertyZexpire_instance)r9r0r0r1<00>_reset_exported-szFromClause._reset_exportedcCs3d|jkr&|j<00>|j<00>n|jj<00>S)akA named-based collection of :class:`.ColumnElement` objects
maintained by this :class:`.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)
rj)<05>__dict__<5F>_init_collections<6E>_populate_column_collectionrjZ as_immutable)r9r0r0r1ro2s 
 zFromClause.columnscCs|j<00>|j<00>|jS)zbReturn the collection of Column objects which comprise the
primary key of this FromClause.)r<>r<>rm)r9r0r0r1rmDs

zFromClause.primary_keycCs|j<00>|j<00>|jS)zUReturn the collection of ForeignKey objects which this
FromClause references.)r<>r<><00> foreign_keys)r9r0r0r1r<>Ms

zFromClause.foreign_keysro<00>docz,An alias for the :attr:`.columns` attribute.cCsgd|jkst<00>d|jks*t<00>d|jks?t<00>t<00>|_t<00>|_t<00>|_dS)Nrjrmr<>)r<><00>AssertionErrorrrjrrmr<>r<>)r9r0r0r1r<>Zs   zFromClause._init_collectionscCs d|jkS)Nrj)r<>)r9r0r0r1<00>_cols_populatedcszFromClause._cols_populatedcCsdS)z<>Called on subclasses to establish the .c collection.
Each implementation has a different way of establishing
this collection.
Nr0)r9r0r0r1r<>gsz&FromClause._populate_column_collectioncCsA|js dS|j|jkr9|j|j|kr9|SdSdS)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<><00>keyro)r9r<>r0r0r1<00>_refresh_for_new_columnos  z"FromClause._refresh_for_new_column)(r;r<r=rRrS<00>named_with_column<6D> _hide_froms<6D>_is_join<69>
_is_select<EFBFBD>_is_from_container<65>_textualZschemar Z!group_expirable_memoized_propertyr<79>Zpending_deprecation<6F> dependenciesrqr6rXrzrLr|rr<>r<>r<>r>r<>r<>rormr<>r#r<><00>_select_iterabler<65>r<>r<>r<>r0r0r0r1rh<00>sH    &&
 I      rhc@s<>eZdZdZdZdZdddd<00>Zeddd <00><00>Zeddd
d <00><00>Z e
d d <00><00>Z dd<00>Z ddd<00>Z ejd<00>dd<00><00>Zdd<00>Zedd<00>Zdd<00>Zdd<00>Zeddddd<00><00>Zedd <00><00>Zed!d"<00><00>Zdd#d$<00>Ze
d%d&<00><00>Zejd<00>ddd'd(<00><00>Ze
d)d*<00><00>Ze
d+d,<00><00>ZdS)-rvawrepresent a ``JOIN`` construct between two :class:`.FromClause`
elements.
The public constructor function for :class:`.Join` is the module-level
:func:`.join()` function, as well as the :meth:`.FromClause.join` method
of any :class:`.FromClause` (e.g. such as :class:`.Table`).
.. seealso::
:func:`.join`
:meth:`.FromClause.join`
rXTNFcCsdt|<00>|_t|<00>j<00>|_|dkrN|j|j|j<00>|_n ||_||_dS)z<>Construct a new :class:`.Join`.
The usual entrypoint here is the :func:`~.expression.join`
function or the :meth:`.FromClause.join` method of any
:class:`.FromClause` object.
N)r2<00>left<66>
self_grouprw<00>_match_primariesrxry)r9r<>rwrxryr0r0r1<00>__init__<5F>s   z Join.__init__cCs||||dd<00>S)a<>Return an ``OUTER JOIN`` clause element.
The returned object is an instance of :class:`.Join`.
Similar functionality is also available via the
:meth:`~.FromClause.outerjoin()` method on any
:class:`.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:`.FromClause.join` or
:meth:`.FromClause.outerjoin` methods on the resulting
:class:`.Join` object.
ryTr0)<04>clsr<73>rwrxr0r0r1<00>_create_outerjoin<69>szJoin._create_outerjoincCs|||||<00>S)a8Produce a :class:`.Join` object, given two :class:`.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:`.FromClause` object (e.g. such as a :class:`.Table`) using
the :meth:`.FromClause.join` method.
:param left: The left side of the join.
:param right: the right side of the join; this is any
:class:`.FromClause` object such as a :class:`.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:`.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.
.. seealso::
:meth:`.FromClause.join` - method form, based on a given left side
:class:`.Join` - the type of object produced
r0)r<>r<>rwrxryr0r0r1<00> _create_join<69>s)zJoin._create_joincCs2d|jjt|j<00>|jjt|j<00>fS)Nz Join object on %s(%d) and %s(%d))r<>r<><00>idrw)r9r0r0r1r<><00>s
   zJoin.descriptioncCs.||kp-|jj|<00>p-|jj|<00>S)N)r<>r|rw)r9rir0r0r1r|s zJoin.is_derived_fromcCs
t|<00>S)N)<01> FromGrouping)r9<00>againstr0r0r1r<>szJoin.self_groupzsqlalchemy.sql.utilcCs<>dd<00>|jjD<>dd<00>|jjD<>}|jj|jdd<00>|D<>|j<00><00>|jjdd<00>|D<><00>|j jt
j dd<00>|D<><00><00>dS)NcSsg|] }|<00>qSr0r0)r]r<>r0r0r1r_ s z4Join._populate_column_collection.<locals>.<listcomp>cSsg|] }|<00>qSr0r0)r]r<>r0r0r1r_ s css|]}|jr|VqdS)N)rm)r]r<>r0r0r1<00> <genexpr>sz3Join._populate_column_collection.<locals>.<genexpr>css|]}|j|fVqdS)N)<01>_label)r]rur0r0r1r<>scSsg|]}|j<00>qSr0)r<>)r]rur0r0r1r_s ) r<>rorwrm<00>extend<6E>reduce_columnsrxrj<00>updater<65><00> itertools<6C>chain)r9r<>ror0r0r1r<>
sz Join._populate_column_collectioncCs<>|jj|<00>}|dkr3|jj|<00>}n|dk r<>|jr<>||j|j<|jj|<00>|jr<>|jj|<00>n|SndS)N) r<>r<>rwr<>rjr<>r<>r<>rm)r9r<>rur0r0r1r<>s    zJoin._refresh_for_new_columncKsM|j<00>||j|<00>|_||j|<00>|_||j|<00>|_dS)N)r<>r<>rwrx)r9<00>clonerZr0r0r1<00>_copy_internals"s
zJoin._copy_internalscKs|j|j|jfS)N)r<>rwrx)r9rNr0r0r1<00> get_children(szJoin.get_childrencCs7t|t<00>r|j}nd}|j||d|<00>S)N<>a_subset)r)rvrw<00>_join_condition)r9r<>rwZ
left_rightr0r0r1r<>+s zJoin._match_primariesc Cs<>|j||||<00>}t|<00>dkrC|j||||<00>nt|<00>dkr<>t|t<00>rmd}nd}tjd|j|j|f<16><00>ndd<00>t|j <00><00>dD<>}t|<00>dkr<>|dSt
|<00>SdS) 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: Deprecated - this
flag is no longer used. Only resolution errors regarding
the two given tables are propagated.
: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".
rr"zI Perhaps you meant to convert the right side to a subquery using alias()?<3F>zACan't find any foreign key relationships between '%s' and '%s'.%scSs"g|]\}}||k<00>qSr0r0)r]<00>x<>yr0r0r1r_bs z(Join._join_condition.<locals>.<listcomp>N) <0B>_joincond_scan_left_rightr<74><00>_joincond_trim_constraintsr)r<>r!ZNoForeignKeysErrorr<72>rn<00>valuesr) r<><00>a<>bZignore_nonexistent_tablesr<73><00>consider_as_foreign_keys<79> constraintsZhint<6E>critr0r0r1r<>2s  #zJoin._join_conditionc
Cs<>tjt<00>}x<>||fD]<5D>}|dkr4qnx<>t|jddd<00><00>D]<5D>}|dk rw|j|krwqPny|j|<00>}WnCtjk
r<>} z | j |j
kr<><00>nwPWYdd} ~ XnX|dk rP||j j ||jf<00>qPqPW||k r<>x<>t|jddd<00><00>D]<5D>}|dk rO|j|krOq(ny|j|<00>}WnCtjk
r<>} z | j |j
kr<><01>nw(WYdd} ~ XnX|dk r(||j j ||jf<00>q(q(Wn|rPqqW|S)Nr<4E>cSs
|jjS)N)<02>parent<6E>_creation_order)<01>fkr0r0r1<00><lambda>rsz0Join._joincond_scan_left_right.<locals>.<lambda>cSs
|jjS)N)r<>r<>)r<>r0r0r1r<><00>s) <0A> collections<6E> defaultdictrn<00>sortedr<64>r<>Z get_referentr!ZNoReferenceErrorZ
table_namerD<00>
constraint<EFBFBD>append)
r<EFBFBD>r<>r<>r<>r<>r<>r<>r<>ruZnrter0r0r1r<>hsH    $    'zJoin._joincond_scan_left_rightcCs<>|rRxIt|<00>D]8}tdd<00>|jD<><00>t|<00>kr||=qqWnt|<00>dkr<>tdd<00>|j<00>D<><00>}t|<00>dkr<>t|<00>d}i|||6}q<>nt|<00>dkr<>tjd|j|jf<16><00>ndS)Ncss|]}|jVqdS)N)r<>)r]<00>fr0r0r1r<><00>sz2Join._joincond_trim_constraints.<locals>.<genexpr>rcss|]}t|<00>VqdS)N)ra)r]r<>r0r0r1r<><00>sr"z<>Can't determine join between '%s' and '%s'; tables have more than one foreign key constraint relationship between them. Please specify the 'onclause' of this join explicitly.)rnr<><00>elementsr<73>r<>r!ZAmbiguousForeignKeysErrorr<72>)r<>r<>r<>r<>r<><00>constZdeduper<65>r0r0r1r<><00>s zJoin._joincond_trim_constraintscKs+|j|jg}t||d|g|<00>S)a"Create a :class:`.Select` from this :class:`.Join`.
The equivalent long-hand form, given a :class:`.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.
rl)r<>rwrK)r9rsrNZcollistr0r0r1r6<00>sz Join.selectcCs|jjp|jjS)N)r<><00>bindrw)r9r0r0r1r<><00>sz Join.bindcCs<>|r<>|dkstd<00><00>|jjdd<00>|jjdd<00>}}|j|<00>j|j|<00><00>}|j||j|j<00>d|j <00>S|j
dddd<00>j|<00>SdS) a8return an alias of this :class:`.Join`.
The default behavior here is to first produce a SELECT
construct from this :class:`.Join`, then to produce an
:class:`.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:`.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:`.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:`.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:`.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:`.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:`.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:`.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::
:func:`~.expression.alias`
Nz"Can't send name argument with flatrPTry<00>
use_labels<EFBFBD> correlateF) r<>r<>rLrwr<>r<>rXr<>rxryr6)r9r<>rDrPZleft_aZright_a<5F>adapterr0r0r1rL<00>sc!
z
Join.aliascCstjdd<00>|jD<><00>S)NcSs%g|]}t|j|j<00><00>qSr0)rr<>rw)r]r<>r0r0r1r_<s z$Join._hide_froms.<locals>.<listcomp>)r<>r<>r{)r9r0r0r1r<>:szJoin._hide_fromscCs%|g|jj|jj|jjS)N)rxrr<>rw)r9r0r0r1r?szJoin._from_objects)r;r<r=rRrSr<>r<><00> classmethodr<64>r<>r>r<>r|r<>r r<>r<>r<>r
r<>r<>r<>r<>r<>r<>r6r<>rLr<>rr0r0r0r1rv<00>s8 *    3- nrvc@s<>eZdZdZdZdZdZddd<00>Zedd<00><00>Z d d
<00>Z
d d <00>Z d d<00>Z dd<00>Z edd<00>Zddd<00>Zedd<00><00>Zedd<00><00>ZdS)r3a<>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:`.FromClause.alias` method available
on all :class:`.FromClause` subclasses.
rLTNcCs<>|}xt|t<00>r$|j}q W||_|j|_|jrR|j|_n||_|dkr<>|jjr<>t|jdd<00>}ntdt |<00>|p<>df<16>}n||_
dS)NrDz
%%(%d %s)sZanon) r)r3r/r4Zsupports_execution<6F>_execution_optionsr<73>r<>rr<>rD)r9r,rD<00>baseselectabler0r0r1r<>Ys       zAlias.__init__cCs'tjr|jS|jjdd<00>SdS)N<>ascii<69>backslashreplace)r <00>py3krD<00>encode)r9r0r0r1r<>is zAlias.descriptionc Cs=y|jj<00>SWn%tk
r8td|j<16><00>YnXdS)Nz)Element %s does not support 'as_scalar()')r/<00> as_scalarr-)r9r0r0r1r<>ps
 zAlias.as_scalarcCs#||jkrdS|jj|<00>S)NT)r{r/r|)r9rir0r0r1r|wszAlias.is_derived_fromcCs+x$|jjjD]}|j|<00>qWdS)N)r/ror<><00> _make_proxy)r9rur0r0r1r<>|sz!Alias._populate_column_collectioncCsC|jj|<00>}|dk r;|js+dS|j|<00>SndSdS)N)r/r<>r<>r<>)r9r<>rur0r0r1r<><00>s   zAlias._refresh_for_new_columncKsjt|jt<00>rdS|j<00>||j|<00>|_|j}xt|t<00>r\|j}qAW||_dS)N)r)r/<00> TableClauser<65>r3r4)r9r<>rZr<>r0r0r1r<><00>s
  zAlias._copy_internalscks.|r"x|jD] }|VqWn|jVdS)N)r<>r/)r9<00>column_collectionsrZr<>r0r0r1r<><00>s zAlias.get_childrencCs|gS)Nr0)r9r0r0r1r<00>szAlias._from_objectscCs
|jjS)N)r/r<>)r9r0r0r1r<><00>sz
Alias.bind)r;r<r=rRrSr<>r<>r<>r>r<>r<>r|r<>r<>r
r<>r<>rr<>r0r0r0r1r3Gs    
 r3cseZdZdZdZddde<00>d<00>fdd<00>Ze<00>fdd<00>Zddd d
<00>Z d d <00>Z
d d<00>Z <00>S)<0F>CTEz<45>Represent a Common Table Expression.
The :class:`.CTE` object is obtained using the
:meth:`.SelectBase.cte` method from any selectable.
See that method for complete examples.
.. versionadded:: 0.7.6
<20>cteNFcsM||_||_||_|r-||_ntt|<00>j|d|<00>dS)NrD)<07> recursive<76>
_cte_alias<EFBFBD> _restatesrf<00>superr<72>r<>)r9r,rDr<>r<>r<>rf)r<>r0r1r<><00>s     z CTE.__init__c s`tt|<00>j<00><00><00>|jdk r4||_nt<00><00>fdd<00>|jD<><00>|_dS)Ncsg|]}<00>|<00><00><00>qSr0r0)r]<00>elem)r<>rZr0r1r_<00>s z'CTE._copy_internals.<locals>.<listcomp>)r<>r<>r<>r<><00> frozensetr<74>)r9r<>rZ)r<>)r<>rZr1r<><00>s
 zCTE._copy_internalsc
Cs+t|jd|d|jd|d|j<00>S)NrDr<>r<>rf)r<>r4r<>rf)r9rDrPr0r0r1rL<00>s   z CTE.aliasc
CsFt|jj|<00>d|jd|jd|jj|g<00>d|j<00>S)NrDr<>r<>rf)r<>r4<00>unionrDr<>r<>rf)r9r~r0r0r1r<><00>s   z CTE.unionc
CsFt|jj|<00>d|jd|jd|jj|g<00>d|j<00>S)NrDr<>r<>rf)r<>r4<00> union_allrDr<>r<>r<>rf)r9r~r0r0r1r<><00>s   z CTE.union_all) r;r<r=rRrSr<>r<>r
r<>rLr<>r<>r0r0)r<>r1r<><00>s  r<>c@s<>eZdZdZdZdd<00>Zdd<00>Zedd<00><00>Zed d
<00><00>Z ed d <00><00>Z
d d<00>Z dd<00>Z edd<00><00>Z dd<00>Zedd<00>Zedd<00><00>Zdd<00>Zdd<00>Zdd<00>ZdS) r<>z%Represent a grouping of a FROM clause<73>groupingcCs ||_dS)N)r/)r9r/r0r0r1r<><00>szFromGrouping.__init__cCsdS)Nr0)r9r0r0r1r<><00>szFromGrouping._init_collectionscCs
|jjS)N)r/ro)r9r0r0r1ro<00>szFromGrouping.columnscCs
|jjS)N)r/rm)r9r0r0r1rm<00>szFromGrouping.primary_keycCs
|jjS)N)r/r<>)r9r0r0r1r<><00>szFromGrouping.foreign_keyscCs|jj|<00>S)N)r/r|)r9r/r0r0r1r|<00>szFromGrouping.is_derived_fromcKst|jj|<00><00>S)N)r<>r/rL)r9rZr0r0r1rL<00>szFromGrouping.aliascCs
|jjS)N)r/r<>)r9r0r0r1r<><00>szFromGrouping._hide_fromscKs
|jfS)N)r/)r9rNr0r0r1r<>szFromGrouping.get_childrencKs||j|<00>|_dS)N)r/)r9r<>rZr0r0r1r<>szFromGrouping._copy_internalscCs
|jjS)N)r/r)r9r0r0r1r szFromGrouping._from_objectscCst|j|<00>S)N)r<>r/)r9<00>attrr0r0r1<00> __getattr__ szFromGrouping.__getattr__cCsi|jd6S)Nr/)r/)r9r0r0r1<00> __getstate__szFromGrouping.__getstate__cCs|d|_dS)Nr/)r/)r9<00>stater0r0r1<00> __setstate__szFromGrouping.__setstate__N)r;r<r=rRrSr<>r<>r>rormr<>r|rLr<>r<>r
r<>rr<>r<>r<>r0r0r0r1r<><00>s        r<>cs<>eZdZdZdZdZdZdZ<00>fdd<00>Zdd <00>Z e
j d
d <00><00>Z d d <00>Z ddd<00>Ze
jd<00>dddd<00><00>Ze
jd<00>ddddd<00><00>Ze
jd<00>ddd<00><00>Zedd<00><00>Z<00>S)r<>aRepresents a minimal "table" construct.
This is a lightweight table object that has only a name and a
collection of columns, which are typically produced
by the :func:`.expression.column` function::
from sqlalchemy import table, column
user = table("user",
column("id"),
column("name"),
column("description"),
)
The :class:`.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:`.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.
<20>tableTFNcsitt|<00>j<00>||_|_t<00>|_t<00>|_t <00>|_
x|D]}|j |<00>qNWdS)aIProduce a new :class:`.TableClause`.
The object returned is an instance of :class:`.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.
N) r<>r<>r<>rD<00>fullnamerrjrrmr<>r<><00> append_column)r9rDror<>)r<>r0r1r<>?s    zTableClause.__init__cCsdS)Nr0)r9r0r0r1r<>YszTableClause._init_collectionscCs'tjr|jS|jjdd<00>SdS)Nr<4E>r<>)r r<>rDr<>)r9r0r0r1r<>\s zTableClause.descriptioncCs||j|j<||_dS)N)rjr<>r)r9r<>r0r0r1rcszTableClause.append_columncKs"|rdd<00>|jD<>SgSdS)NcSsg|] }|<00>qSr0r0)r]r<>r0r0r1r_is z,TableClause.get_children.<locals>.<listcomp>)r<>)r9r<>rNr0r0r1r<>gszTableClause.get_childrenzsqlalchemy.sql.dmlcKs|j|d|d||<00>S)z<>Generate an :func:`.insert` construct against this
:class:`.TableClause`.
E.g.::
table.insert().values(name='foo')
See :func:`.insert` for argument and usage information.
r<><00>inline)ZInsert)r9<00>dmlr<6C>rrNr0r0r1<00>insertms zTableClause.insertc Ks"|j|d|d|d||<00>S)z<>Generate an :func:`.update` construct against this
:class:`.TableClause`.
E.g.::
table.update().where(table.c.id==7).values(name='foo')
See :func:`.update` for argument and usage information.
rsr<>r)ZUpdate)r9rrsr<>rrNr0r0r1r<>|szTableClause.updatecKs|j|||<00>S)z<>Generate a :func:`.delete` construct against this
:class:`.TableClause`.
E.g.::
table.delete().where(table.c.id==7)
See :func:`.delete` for argument and usage information.
)ZDelete)r9rrsrNr0r0r1<00>delete<74>s zTableClause.deletecCs|gS)Nr0)r9r0r0r1r<00>szTableClause._from_objects)r;r<r=rRrSr<>Zimplicit_returningZ_autoincrement_columnr<6E>r<>r Zmemoized_propertyr<79>rr<>r<>rr<>rr>rr0r0)r<>r1r<>s"      r<>c@sXeZdZedd<00><00>Zedd<00><00>Zedd<00>Zdddd d
<00>Z dS) <0B> ForUpdateArgcCs<>|dkrdSd}}|dkr/d}nP|dkrDd}n;|dkr]d}}n"|dk rtjd|<16><00>ntd|d|<00>S) a<>Parse the for_update arugment of :func:`.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).
NF<4E>nowaitT<74>read<61> read_nowaitzUnknown for_update argument: %r)NF)r!r.r)r9<00>argrr r0r0r1<00>parse_legacy_select<63>s 
       z ForUpdateArg.parse_legacy_selectcCsB|jr|j rdS|jr-|jr-dS|jr:dSdSdS)Nr r
rT)r r)r9r0r0r1<00>legacy_for_update_value<75>s z$ForUpdateArg.legacy_for_update_valuec s8|jdk r4<00><00>fdd<00>|jD<>|_ndS)Ncsg|]}<00>|<00><00><00>qSr0r0)r]ru)r<>rZr0r1r_<00>s z0ForUpdateArg._copy_internals.<locals>.<listcomp>)<01>of)r9r<>rZr0)r<>rZr1r<><00>szForUpdateArg._copy_internalsFNcCsM||_||_|dk r@dd<00>tj|<00>D<>|_n d|_dS)zgRepresents arguments specified to :meth:`.Select.for_update`.
.. versionadded:: 0.9.0
NcSsg|]}t|<00><00>qSr0)r )r]r<>r0r0r1r_<00>s z)ForUpdateArg.__init__.<locals>.<listcomp>)rr r <00>to_listr)r9rr rr0r0r1r<><00>s     zForUpdateArg.__init__)
r;r<r=r<>r r>r r
r<>r<>r0r0r0r1r<00>s % rc@s<>eZdZdZdd<00>Zdd<00>Zdddd <00>Zeej d
d d <00>d d<00><00><00>Z
dd<00>Z e dd<00><00>Z dS)r5z<>Base class for SELECT statements.
This includes :class:`.Select`, :class:`.CompoundSelect` and
:class:`.TextAsFrom`.
cCs
t|<00>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`.
)<01> ScalarSelect)r9r0r0r1r<><00>s zSelectBase.as_scalarcCs|j<00>j|<00>S)z<>return a 'scalar' representation of this selectable, embedded as a
subquery with a label.
.. seealso::
:meth:`~.SelectBase.as_scalar`.
)r<>rr)r9rDr0r0r1rr<00>s zSelectBase.labelNFcCst|d|d|<00>S)aUReturn a new :class:`.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.
SQLAlchemy detects :class:`.CTE` objects, which are treated
similarly to :class:`.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.
.. versionadded:: 0.7.6
:param name: name given to the common table expression. Like
:meth:`._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 illustrate two examples from
Postgresql's documentation at
http://www.postgresql.org/docs/8.4/static/queries-with.html.
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()
.. seealso::
:meth:`.orm.query.Query.cte` - ORM version of
:meth:`.SelectBase.cte`.
rDr<>)r<>)r9rDr<>r0r0r1r<>suzSelectBase.ctez0.6rkze``autocommit()`` is deprecated. Use :meth:`.Executable.execution_options` with the 'autocommit' flag.cCs |jjidd6<>|_dS)zPreturn a new selectable with the 'autocommit' flag set to
True.
T<>
autocommitN)r<>r<>)r9r0r0r1rs zSelectBase.autocommitcCs5|jj|j<00>}|jj<00>|_|j<00>|S)zWOverride the default _generate() method to also clear out
exported collections.)r<><00>__new__r<5F><00>copyr<79>)r9<00>sr0r0r1<00> _generate<74>s
zSelectBase._generatecCs|gS)Nr0)r9r0r0r1r<00>szSelectBase._from_objects)r;r<r=rRr<>rrr<>rr Z
deprecatedrrr>rr0r0r0r1r5<00>s  w  r5c
@s{eZdZdZe<00>Ze<00>ZdZdZdZ dddddddddd<00>Z
e dd<00><00>Z e j dd<00><00>Z edddd d
<00><00>Zed d <00><00>Ze d d<00><00>Ze dd<00><00>Ze dd<00><00>Ze dd<00><00>Zedd<00><00>Zedd<00><00>Zedd<00><00>Zedd<00><00>Zdd<00>Zdd <00>Ze d!d"<00><00>Zed#d$<00>ZdS)%<25>GenerativeSelecta<74>Base class for SELECT statements where additional elements can be
added.
This serves as the base for :class:`.Select` and :class:`.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:`.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:`.GenerativeSelect` was added to
provide functionality specific to :class:`.Select` and
:class:`.CompoundSelect` while allowing :class:`.SelectBase` to be
used for other SELECT-like objects, e.g. :class:`.TextAsFrom`.
NFc Cs||_|dk r*tj|<00>|_n|dk rbtjd<00>|jji|d6<>|_n|dk r<>t|<00>|_ n|dk r<>t|<00>|_
n||_ |dk r<>t dt tj|<00><00>|_n|dk rt dttj|<00><00>|_ndS)NFzNautocommit on select() is deprecated. Use .execution_options(autocommit=True)rr )r<>rr <00>_for_update_argr Zwarn_deprecatedr<64>r<>rF<00> _limit_clause<73>_offset_clause<73>_bindrrr<00>_order_by_clauser<00>_group_by_clause) r9r<><00>
for_update<EFBFBD>limit<69>offset<65>order_by<62>group_byr<79>rr0r0r1r<><00>s$          zGenerativeSelect.__init__cCs!|jdk r|jjSdSdS)zIProvide legacy dialect support for the ``for_update`` attribute.
N)rr )r9r0r0r1r<00>s
zGenerativeSelect.for_updatecCstj|<00>|_dS)N)rr r)r9rEr0r0r1r<00>scCs"td|d|d|<00>|_dS)aSSpecify a ``FOR UPDATE`` clause for this :class:`.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:`.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.
.. versionadded:: 0.9.0
rr rN)rr)r9rr rr0r0r1<00>with_for_update<74>s'z GenerativeSelect.with_for_updatecCs 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<>)r9r0r0r1<00> apply_labels s zGenerativeSelect.apply_labelscCst|jd<00>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.
r)rJr)r9r0r0r1<00>_limitszGenerativeSelect._limitcCst|jt<00>S)zqTrue if the LIMIT clause is a simple integer, False
if it is not present or is a SQL expression.
)r)rr8)r9r0r0r1<00>_simple_int_limit#sz"GenerativeSelect._simple_int_limitcCst|jt<00>S)zrTrue if the OFFSET clause is a simple integer, False
if it is not present or is a SQL expression.
)r)rr8)r9r0r0r1<00>_simple_int_offset*sz#GenerativeSelect._simple_int_offsetcCst|jd<00>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.
r)rJr)r9r0r0r1<00>_offset1szGenerativeSelect._offsetcCst|<00>|_dS)a&return a new selectable with the given LIMIT criterion
applied.
This is a numerical value which usually renders as a ``LIMIT``
expression in the resulting select. Backends that don't
support ``LIMIT`` will attempt to provide similar
functionality.
.. versionchanged:: 1.0.0 - :meth:`.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)rFr)r9rr0r0r1r;szGenerativeSelect.limitcCst|<00>|_dS)a-return a new selectable with the given OFFSET criterion
applied.
This is a numeric value which usually renders as an ``OFFSET``
expression in the resulting select. Backends that don't
support ``OFFSET`` will attempt to provide similar
functionality.
.. versionchanged:: 1.0.0 - :meth:`.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)rFr)r9rr0r0r1rOszGenerativeSelect.offsetcGs|j|<00>dS)z<>return a new selectable with the given list of ORDER BY
criterion applied.
The criterion will be appended to any pre-existing ORDER BY
criterion.
N)<01>append_order_by)r9<00>clausesr0r0r1r es
zGenerativeSelect.order_bycGs|j|<00>dS)z<>return a new selectable with the given list of GROUP BY
criterion applied.
The criterion will be appended to any pre-existing GROUP BY
criterion.
N)<01>append_group_by)r9r)r0r0r1r!qs
zGenerativeSelect.group_bycGs~t|<00>dkr1|ddkr1t<00>|_nIt|dd<00>dk ret|j<00>t|<00>}ntdt|<00>|_dS)aIAppend 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:`~.GenerativeSelect.order_by` method is preferred, as it
provides standard :term:`method chaining`.
rr"Nrr )r<>rrr<>rnr)r9r)r0r0r1r(}s
"z GenerativeSelect.append_order_bycGs~t|<00>dkr1|ddkr1t<00>|_nIt|dd<00>dk ret|j<00>t|<00>}ntdt|<00>|_dS)aIAppend 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:`~.GenerativeSelect.group_by` method is preferred, as it
provides standard :term:`method chaining`.
rr"Nrr )r<>rrr<>rnr)r9r)r0r0r1r*<00>s
"z GenerativeSelect.append_group_bycCs t<00><00>dS)N)<01>NotImplementedError)r9r0r0r1<00>_label_resolve_dict<63>sz$GenerativeSelect._label_resolve_dictcKsR|jdk r'||j|<00>|_n|jdk rN||j|<00>|_ndS)N)rr)r9r<>rZr0r0r1r<><00>sz GenerativeSelect._copy_internals)r;r<r=rRrrrrrrr<>r>r<00>setterrr"r#r$r%r&r'rrr r!r(r*r,r
r<>r0r0r0r1r<00>s>    ( 

   rcs<>eZdZdZdZejd<00>Zejd<00>Zejd<00>Z ejd<00>Z
ejd<00>Z ejd<00>Z d Z d
d <00>Zed d <00><00>Zedd<00><00>Zedd<00><00>Zedd<00><00>Zedd<00><00>Zedd<00><00>Zedd<00><00>Zdd<00>Zddd<00>Zdd <00>Zd!d"<00>Zd#d$<00>Ze<00>fd%d&<00>Zd d'd(<00>Zd)d*<00>Z d+d,<00>Z!ee e!<00>Z <00>S)-<2D>CompoundSelectaForms the basis of ``UNION``, ``UNION ALL``, and other
SELECT-based set operations.
.. seealso::
:func:`.union`
:func:`.union_all`
:func:`.intersect`
:func:`.intersect_all`
:func:`.except`
:func:`.except_all`
Zcompound_select<63>UNIONz UNION ALL<4C>EXCEPTz
EXCEPT ALL<4C> INTERSECTz INTERSECT ALLTcOs<>|jdd<00>|_||_g|_d}x<>t|<00>D]<5D>\}}t|<00>}|smt|jj<00>}n]t|jj<00>|kr<>t j
ddt|jdjj<00>|dt|jj<00>f<16><00>n|jj |j |<00><00>q:Wt j||<00>dS)Nr<4E>Fz}All selectables passed to CompoundSelect must have identical numbers of columns; select #%d has %d columns, select #%d has %drr")rW<00>_auto_correlate<74>keyword<72>selects<74> enumeraterr<>r<>r<>r!r.r<>r<>rr<>)r9r3r4rNZnumcols<6C>nrr0r0r1r<><00>s   #zCompoundSelect.__init__cCs&tdd<00>|jD<><00>}||fS)Ncss|]}|j|fVqdS)N)r<>)r]r<>r0r0r1r<><00>sz5CompoundSelect._label_resolve_dict.<locals>.<genexpr>)<02>dictr<74>)r9<00>dr0r0r1r,<00>sz"CompoundSelect._label_resolve_dictcOsttj||<00>S)a<>Return a ``UNION`` of multiple selectables.
The returned object is an instance of
:class:`.CompoundSelect`.
A similar :func:`union()` method is available on all
:class:`.FromClause` subclasses.
\*selects
a list of :class:`.Select` instances.
\**kwargs
available keyword arguments are the same as those of
:func:`select`.
)r.r/)r<>r4rNr0r0r1<00> _create_union<6F>szCompoundSelect._create_unioncOsttj||<00>S)a<>Return a ``UNION ALL`` of multiple selectables.
The returned object is an instance of
:class:`.CompoundSelect`.
A similar :func:`union_all()` method is available on all
:class:`.FromClause` subclasses.
\*selects
a list of :class:`.Select` instances.
\**kwargs
available keyword arguments are the same as those of
:func:`select`.
)r.<00> UNION_ALL)r<>r4rNr0r0r1<00>_create_union_allsz CompoundSelect._create_union_allcOsttj||<00>S)a7Return an ``EXCEPT`` of multiple selectables.
The returned object is an instance of
:class:`.CompoundSelect`.
\*selects
a list of :class:`.Select` instances.
\**kwargs
available keyword arguments are the same as those of
:func:`select`.
)r.r0)r<>r4rNr0r0r1<00>_create_exceptszCompoundSelect._create_exceptcOsttj||<00>S)a;Return an ``EXCEPT ALL`` of multiple selectables.
The returned object is an instance of
:class:`.CompoundSelect`.
\*selects
a list of :class:`.Select` instances.
\**kwargs
available keyword arguments are the same as those of
:func:`select`.
)r.<00>
EXCEPT_ALL)r<>r4rNr0r0r1<00>_create_except_all(sz!CompoundSelect._create_except_allcOsttj||<00>S)a:Return an ``INTERSECT`` of multiple selectables.
The returned object is an instance of
:class:`.CompoundSelect`.
\*selects
a list of :class:`.Select` instances.
\**kwargs
available keyword arguments are the same as those of
:func:`select`.
)r.r1)r<>r4rNr0r0r1<00>_create_intersect9sz CompoundSelect._create_intersectcOsttj||<00>S)a>Return an ``INTERSECT ALL`` of multiple selectables.
The returned object is an instance of
:class:`.CompoundSelect`.
\*selects
a list of :class:`.Select` instances.
\**kwargs
available keyword arguments are the same as those of
:func:`select`.
)r.<00> INTERSECT_ALL)r<>r4rNr0r0r1<00>_create_intersect_allJsz$CompoundSelect._create_intersect_allcCs|jdj<00>S)Nr")r4<00> _scalar_type)r9r0r0r1rB\szCompoundSelect._scalar_typeNcCs
t|<00>S)N)r<>)r9r<>r0r0r1r<>_szCompoundSelect.self_groupcCs+x$|jD]}|j|<00>r
dSq
WdS)NTF)r4r|)r9rirr0r0r1r|bszCompoundSelect.is_derived_fromcCs<>x<>tdd<00>|jD<><00>D]m}|dj|d|jrI|djndd|jre|djnd<00>}dd<00>t|<00>D<>|_qWdS)NcSsg|]}|jj<00>qSr0)r<>r<>)r]rr0r0r1r_is z>CompoundSelect._populate_column_collection.<locals>.<listcomp>r"rDr<>cSs0g|]&\}}|ji|dd6<><00>qS)rr<>)Z _annotate)r]r<>r<>r0r0r1r_<00>s )<08>zipr4r<>r<>r<><00>
_key_labelr5<00>_proxies)r9r<><00>proxyr0r0r1r<>hs
#
" z*CompoundSelect._populate_column_collectioncCs>x|jD]}|j|<00>q
W|js.dStd<00><00>dS)NzUCompoundSelect constructs don't support addition of columns to underlying selectables)r4r<>r<>r+)r9r<>rr0r0r1r<><00>s
 z&CompoundSelect._refresh_for_new_columnc s<>tt|<00>j<00><00><00>|j<00><01><00>fdd<00>|jD<>|_t|d<00>r]|`nxHdD]@}t||<00>dk rdt||<00>t||<00><00><00><00>qdqdWdS)Ncsg|]}<00>|<00><00><00>qSr0r0)r]r)r<>rZr0r1r_<00>s z2CompoundSelect._copy_internals.<locals>.<listcomp><3E>_col_maprrr)z_order_by_clausez_group_by_clausez_for_update_arg) r<>r.r<>r<>r4rBrGr<><00>setattr)r9r<>rZr<>)r<>)r<>rZr1r<><00>s
" 
zCompoundSelect._copy_internalscKs6|rt|j<00>pg|j|jgt|j<00>S)N)rnr<>rrr4)r9r<>rNr0r0r1r<><00>szCompoundSelect.get_childrencCs?|jr|jSx(|jD]}|j}|r|SqWdSdS)N)rr4r<>)r9r<00>er0r0r1r<><00>s  zCompoundSelect.bindcCs ||_dS)N)r)r9r<>r0r0r1<00> _set_bind<6E>szCompoundSelect._set_bind)"r;r<r=rRrSr <00>symbolr/r:r0r=r1r@r<>r<>r>r,r<>r9r;r<r>r?rArBr<>r|r<>r<>r
r<>r<>r<>rJr0r0)r<>r1r.<00>s6       
r.c
seZdZdZdZfZfZej<00>Z fZ
dZ dZ fZ dZejZdZdddddddddd<00>Zedd <00><00>Zddd
d <00>Zd d <00>Zedd<00><00>Zddd<00>Zeddd<00><00>Zedd<00><00>Zejdd<00><00>Zedd<00><00>Zedd<00><00>Zdd<00>Z e!<00>fdd <00>Z"dd!d"<00>Z#ed#d$<00><00>Z$ej%d%<00>dd&d'<00><00>Z&ed(d)<00><00>Z'ed*d+<00><00>Z(ed,d-<00><00>Z)ed.d/<00><00>Z*ed0d1<00><00>Z+ed2d3<00><00>Z,ed4d5<00><00>Z-d6d7<00>Z.d8d9<00>Z/d:d;<00>Z0d<d=<00>Z1d>d?<00>Z2d@dA<00>Z3edBdC<00><00>Z4dDdE<00>Z5dFdG<00>Z6ddHdI<00>Z7dJdK<00>Z8dLdM<00>Z9dNdO<00>Z:dPdQ<00>Z;dRdS<00>Z<dTdU<00>Z=dVdW<00>Z>dXdY<00>Z?ee>e?<00>Z><00>S)ZrKz(Represents a ``SELECT`` statement.
r6FNTc Ks<>||_|dk rO|dkr-d|_qOdd<00>tj|<00>D<>|_n|dk r<>tjdd<00>tj|<00>D<><00>|_ntj<00>|_yt|<00>}
Wn!tk
r<>tj d<00><00>YnX|
r/g|_
x]|D]I} t | <00>} t | t <00>r| jd tj<00>} n|j
j| <00>q<>Wn g|_
|dk ret|<00>jd tj<00>|_n d|_|dk r<>t|<00>jd tj<00>|_n d|_|r<>|j|<00>n|r<>|j|<00>ntj|| <00>dS)
aConstruct a new :class:`.Select`.
Similar functionality is also available via the
:meth:`.FromClause.select` method on any :class:`.FromClause`.
All arguments which accept :class:`.ClauseElement` arguments also
accept string arguments, which will be converted as appropriate into
either :func:`text()` or :func:`literal_column()` constructs.
.. seealso::
:ref:`coretutorial_selecting` - Core Tutorial description of
:func:`.select`.
:param columns:
A list of :class:`.ColumnElement` or :class:`.FromClause`
objects which will form the columns clause of the resulting
statement. For those objects that are instances of
:class:`.FromClause` (typically :class:`.Table` or :class:`.Alias`
objects), the :attr:`.FromClause.c` collection is extracted
to form a collection of :class:`.ColumnElement` objects.
This parameter will also accept :class:`.Text` constructs as
given, as well as ORM-mapped classes.
.. note::
The :paramref:`.select.columns` parameter is not available
in the method form of :func:`.select`, e.g.
:meth:`.FromClause.select`.
.. seealso::
:meth:`.Select.column`
:meth:`.Select.with_only_columns`
:param whereclause:
A :class:`.ClauseElement` expression which will be used to form the
``WHERE`` clause. It is typically preferable to add WHERE
criterion to an existing :class:`.Select` using method chaining
with :meth:`.Select.where`.
.. seealso::
:meth:`.Select.where`
:param from_obj:
A list of :class:`.ClauseElement` objects which will be added to the
``FROM`` clause of the resulting statement. This is equivalent
to calling :meth:`.Select.select_from` using method chaining on
an existing :class:`.Select` object.
.. seealso::
:meth:`.Select.select_from` - full description of explicit
FROM clause specification.
:param autocommit:
Deprecated. Use ``.execution_options(autocommit=<True|False>)``
to set the autocommit option.
.. seealso::
:meth:`.Executable.execution_options`
:param bind=None:
an :class:`~.Engine` or :class:`~.Connection` instance
to which the
resulting :class:`.Select` object will be bound. The
:class:`.Select` object will otherwise automatically bind to
whatever :class:`~.base.Connectable` instances can be located within
its contained :class:`.ClauseElement` members.
:param correlate=True:
indicates that this :class:`.Select` object should have its
contained :class:`.FromClause` elements "correlated" to an enclosing
:class:`.Select` object. It is typically preferable to specify
correlations on an existing :class:`.Select` construct using
:meth:`.Select.correlate`.
.. seealso::
:meth:`.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:`.Select`
object via the :meth:`~.Select.distinct` method.
.. seealso::
:meth:`.Select.distinct`
:param for_update=False:
when ``True``, applies ``FOR UPDATE`` to the end of the
resulting statement.
.. deprecated:: 0.9.0 - use
:meth:`.Select.with_for_update` to specify the
structure of the ``FOR UPDATE`` clause.
``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:`.Select.with_for_update` - improved API for
specifying the ``FOR UPDATE`` clause.
:param group_by:
a list of :class:`.ClauseElement` objects which will comprise the
``GROUP BY`` clause of the resulting select. This parameter
is typically specified more naturally using the
:meth:`.Select.group_by` method on an existing :class:`.Select`.
.. seealso::
:meth:`.Select.group_by`
:param having:
a :class:`.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:`.Select.having` method on an existing :class:`.Select`.
.. seealso::
:meth:`.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:`.Select.limit` method on an existing
:class:`.Select`.
.. seealso::
:meth:`.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:`.Select.offset` method on an existing
:class:`.Select`.
.. seealso::
:meth:`.Select.offset`
:param order_by:
a scalar or list of :class:`.ClauseElement` objects which will
comprise the ``ORDER BY`` clause of the resulting select.
This parameter is typically specified more naturally using the
:meth:`.Select.order_by` method on an existing :class:`.Select`.
.. seealso::
:meth:`.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:`.Select` object will use these
names as well for targeting column members.
This parameter can also be specified on an existing
:class:`.Select` object using the :meth:`.Select.apply_labels`
method.
.. seealso::
:meth:`.Select.apply_labels`
FTcSsg|]}t|<00><00>qSr0)r )r]rIr0r0r1r_<00> s z#Select.__init__.<locals>.<listcomp>Ncss|]}t|<00>VqdS)N)r2)r]r<>r0r0r1r<><00> sz"Select.__init__.<locals>.<genexpr>zDcolumns argument to select() must be a Python list or other iterabler<65>)r2<00> _distinctr r<00>
OrderedSet<EFBFBD> _from_obj<62>bool<6F> TypeErrorr!r.<00> _raw_columnsr r)rr<>r$<00>comma_opr<70>r Z_asbool<6F> _whereclause<73>_havingrYrdrr<>) r9rorsrl<00>distinct<63>havingr<67>rbrgrNZ cols_presentr<74>r0r0r1r<><00>sD<00>             !  ! zSelect.__init__cCs<>g}t<00>}|j}x<>tjt|j<00>|jdk rKt|j<00>nf|j<00>D]u}||kr|tj d<00><00>n|r<>||kr<>||}n|j
|j <00>s<>|j |<00>n|j |j <00>qXW|S)Nz-select() construct refers to itself as a FROM)r<><00> _from_clonedr<64>r<>rrQrSrNr!<00>InvalidRequestErrorr}r{r<>r<>)r9<00>froms<6D>seen<65> translate<74>itemr0r0r1<00>_froms<6D> s     !   z Select._fromscsY<00>j<00>ttjdd<00><00>D<><00><00><00><00>r<><00>jri<00>j<00>fdd<00><00>j<00>j<00>D<><00>n<00>fdd<00><00>D<><00>n<00>jr<><00>j<00><00>r<><00><00><00>fdd<00><00>D<><00>q<>n<00>jdk r<><00><00><00>fdd<00><00>D<><00>n<00>j rU<01>rUt
<00><00>d krU<01><00>fd
d<00><00>D<><00>t
<00><00>sUt j d <00><16><00>qUn<00>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.
cSsg|]}t|j<00><00>qSr0)r r<>)r]r<>r0r0r1r_<00> s z-Select._get_display_froms.<locals>.<listcomp>c3s2|](}<00>j|j|<00>r<00>j|VqdS)N)rWr)r]r<>)r9r0r1r<><00> sz,Select._get_display_froms.<locals>.<genexpr>cs"g|]}|<00>kr|<00>qSr0r0)r]r<>)<01>toremover0r1r_<00> s cs:g|]0}|tt<00><00>p!f<00><00><00>kr|<00>qSr0)r)r]r<>)<03>explicit_correlate_fromsrY<00> to_correlater0r1r_<00> s
Ncs=g|]3}|tt<00><00>p!f<00><00>j<00>kr|<00>qSr0)rr<00>_correlate_except)r]r<>)r_rYr9r0r1r_
s
rcs+g|]!}|t<00><00><00>kr|<00>qSr0)r)r]r<>)rY<00>implicit_correlate_fromsr0r1r_
s z<>Select statement '%s' returned no FROM clauses due to auto-correlation; specify correlate(<tables>) to control correlation manually.) r]r<>r<>r<>rWr<>r}<00>
_correlaterar2r<>r!rX)r9r_rbr0)r_rYrbr9r`r^r1<00>_get_display_froms<6D> s0
     %"   zSelect._get_display_fromscCs'|jd}t|j<00>}|djS)Nr")rQrnr<><00>type)r9r<>r<>r0r0r1rB#
s zSelect._scalar_typecCs
|j<00>S)z1Return the displayed list of FromClause elements.)rd)r9r0r0r1rY(
sz Select.froms<6D>*cCs|jd||<00>S)a<>add a statement hint to this :class:`.Select`.
This method is similar to :meth:`.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:`.Select.with_hint`
N)<01> with_hint)r9<00>text<78> dialect_namer0r0r1<00>with_statement_hint.
szSelect.with_statement_hintcCsM|dkr'|j||ff7_n"|jji|||f6<>|_dS)a<>Add an indexing or other executional context hint for the given
selectable to this :class:`.Select`.
The text of the hint is rendered in the appropriate
location for the database backend in use, relative
to the given :class:`.Table` or :class:`.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:`.Select.with_statement_hint`
N)<03>_statement_hints<74>_hintsr<73>)r9r,rhrir0r0r1rgB
s"  zSelect.with_hintcCstjd<00><00>dS)NzvSelect objects don't have a type. Call as_scalar() on this Select object to return a 'scalar' version of this Select.)r!rX)r9r0r0r1rej
sz Select.typecCs|j}|tt|<00><00>S)z<>return a Set of all 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]rnr)r9rYr0r0r1<00>locate_all_fromsq
s zSelect.locate_all_fromscCs t|j<00>S)z<>an iterator of all ColumnElement expressions which would
be rendered into the columns clause of the resulting SELECT statement.
)rrQ)r9r0r0r1<00> inner_columns}
szSelect.inner_columnscCs{tdd<00>t|j<00>D<><00>}tdd<00>t|j<00>D<><00>}x*|j<00>D]\}}|j||<00>qQW||fS)Ncss9|]/}|jr|jp*|jp*|j|fVqdS)N)<04>_allow_label_resolveZ_resolve_labelr<6C>r<>)r]r<>r0r0r1r<><00>
sz-Select._label_resolve_dict.<locals>.<genexpr>css'|]}|jr|j|fVqdS)N)ror<>)r]r<>r0r0r1r<><00>
s)r7rrQrY<00>items<6D>
setdefault)r9Z with_colsZ
only_fromsr<EFBFBD>rEr0r0r1r,<00>
s  zSelect._label_resolve_dictcCsA||jkrdSx'|j<00>D]}|j|<00>r dSq WdS)NTF)r{rmr|)r9rir<>r0r0r1r|<00>
s zSelect.is_derived_fromc s%tt|<00>j<00><00><00>t<00><00>fdd<00>|jj|j<00>D<><00>|_<00>tj <00>fdd<00>|jD<><00>|_t
<00>fdd<00>|j D<><00>j|j <00>|_ <00><00>fdd<00>|j D<>|_ xHd D]@}t ||<00>dk r<>t||<00>t ||<00><00><00><00>q<>q<>W|j<00>dS) Nc3s$|]}|<00>|<00><00>fVqdS)Nr0)r]r<>)r<>rZr0r1r<><00>
sz)Select._copy_internals.<locals>.<genexpr>c3s|]}<00>|VqdS)Nr0)r]r<>)<01> from_clonedr0r1r<><00>
sc3s|]}<00>|<00>VqdS)Nr0)r]r<>)r<>r0r1r<><00>
scsg|]}<00>|<00><00><00>qSr0r0)r]r<>)r<>rZr0r1r_<00>
s z*Select._copy_internals.<locals>.<listcomp>rSrTrrr)z _whereclausez_havingz_order_by_clausez_group_by_clausez_for_update_arg)r<>rKr<>r7rNr<>r]rWr rMr<>rcrQr<>rHr<>)r9r<>rZr<>)r<>)r<>rrrZr1r<><00>
s 5 1"
)zSelect._copy_internalscKsV|rt|j<00>pg|jt|j<00>dd<00>|j|j|j|jfD<>S)z=return child elements as per the ClauseElement specification.cSs"g|]}|dk r|<00>qS)Nr0)r]r<>r0r0r1r_<00>
s z'Select.get_children.<locals>.<listcomp>)rnrorQr]rSrTrr)r9r<>rNr0r0r1r<><00>
s,  zSelect.get_childrencCs|j|<00>dS)zsreturn a new select() construct with the given column expression
added to its columns clause.
N)r)r9r<>r0r0r1r<><00>
sz Select.columnzsqlalchemy.sql.utilcCs5|j|j|jd||jft|j<00><17><01>S)aReturn a new :func`.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:`.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 eqivalence, 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.
.. versionadded:: 0.8
<20> only_synonyms)<06>with_only_columnsr<73>rnrSrarN)r9r<>rsr0r0r1r<><00>
s
 zSelect.reduce_columnscCsn|j<00>g}xN|D]F}t|<00>}t|t<00>rP|jdtj<00>}n|j|<00>qW||_dS)arReturn a new :func:`.select` construct with its columns
clause replaced with the given columns.
.. versionchanged:: 0.7.3
Due to a bug fix, this method has a slight
behavioral change as of version 0.7.3.
Prior to version 0.7.3, the FROM clause of
a :func:`.select` was calculated upfront and as new columns
were added; in 0.7.3 and later it's calculated
at compile time, fixing an issue regarding late binding
of columns to parent tables. This changes the behavior of
:meth:`.Select.with_only_columns` in that FROM clauses no
longer represented in the new list are dropped,
but this behavior is more consistent in
that the FROM clauses are consistently derived from the
current columns clause. The original intent of this method
is to allow trimming of the existing columns list to be fewer
columns than originally present; the use case of replacing
the columns list with an entirely different one hadn't
been anticipated until 0.7.3 was released; the usage
guidelines below illustrate how this should be done.
This method is exactly equivalent to as if the original
:func:`.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:`.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:`.Select.with_only_columns`.
Since the method is essentially equivalent to calling the
:func:`.select` construct in the first place with the given
columns, the columns passed to :meth:`.Select.with_only_columns`
should usually be a subset of those which were passed
to the :func:`.select` construct, not those which are available
from the ``.c`` collection of that :func:`.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:`.select` construct is essentially being
asked to select both from ``table1`` as well as itself.
r<>N) r<>r r)rr<>r$rRr<>rQ)r9ro<00>rcr<63>r0r0r1rt<00>
sX
  zSelect.with_only_columnscCs|j|<00>dS)z<>return a new select() construct with the given expression added to
its WHERE clause, joined to the existing clause via AND, if any.
N)<01>append_whereclause)r9rsr0r0r1<00>where\ sz Select.wherecCs|j|<00>dS)z<>return a new select() construct with the given expression added to
its HAVING clause, joined to the existing clause via AND, if any.
N)<01> append_having)r9rVr0r0r1rVe sz Select.havingcGsW|rJdd<00>|D<>}t|jt<00>r>|j||_qS||_n d|_dS)a Return a new 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.
cSsg|]}t|<00><00>qSr0)r)r]rIr0r0r1r_x s z#Select.distinct.<locals>.<listcomp>TN)r)rLrn)r9r'r0r0r1rUm s
 zSelect.distinctcCs|j|<00>dS)a<>return a new :func:`.select` construct with the
given FROM expression
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:`.Table` or other selectable
will have no effect. Passing a :class:`.Join` that refers
to an already present :class:`.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:`.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)<01> append_from)r9rir0r0r1<00> select_from<6F> s zSelect.select_fromcGsWd|_|r+|ddkr+f|_n(t|j<00>jdd<00>|D<><00>|_dS)a<>
return a new :class:`.Select` which will correlate the given FROM
clauses to that of an enclosing :class:`.Select`.
Calling this method turns off the :class:`.Select` object's
default behavior of "auto-correlation". Normally, FROM elements
which appear in a :class:`.Select` that encloses this one via
its :term:`WHERE clause`, ORDER BY, HAVING or
:term:`columns clause` will be omitted from this :class:`.Select`
object's :term:`FROM clause`.
Setting an explicit correlation collection using the
:meth:`.Select.correlate` method provides a fixed list of FROM objects
that can potentially take place in this process.
When :meth:`.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:`.Select`
object is, relative to an enclosing :class:`.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:`.Select`. Multi-level correlation ensures that the link
between enclosed and enclosing :class:`.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:`.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:`.FromClause`
constructs, or other compatible constructs (i.e. ORM-mapped
classes) to become part of the correlate collection.
.. versionchanged:: 0.8.0 ORM-mapped classes are accepted by
:meth:`.Select.correlate`.
.. versionchanged:: 0.8.0 The :meth:`.Select.correlate` method no
longer unconditionally removes entries from the FROM clause;
instead, the candidate FROM entries must also be matched by a FROM
entry located in an enclosing :class:`.Select`, which ultimately
encloses this one as present in the WHERE clause, ORDER BY clause,
HAVING clause, or columns clause of an enclosing :meth:`.Select`.
.. versionchanged:: 0.8.2 explicit correlation takes place
via any level of nesting of :class:`.Select` objects; in previous
0.8 versions, correlation would only occur relative to the
immediate enclosing :class:`.Select` construct.
.. seealso::
:meth:`.Select.correlate_except`
:ref:`correlated_subqueries`
Fr"Ncss|]}t|<00>VqdS)N)r2)r]r<>r0r0r1r<><00> sz#Select.correlate.<locals>.<genexpr>)r2rcr<>r<>)r9<00> fromclausesr0r0r1r<><00> s
8  zSelect.correlatecGs]d|_|r+|ddkr+f|_n.t|jp:f<00>jdd<00>|D<><00>|_dS)a<>return a new :class:`.Select` which will omit the given FROM
clauses from the auto-correlation process.
Calling :meth:`.Select.correlate_except` turns off the
:class:`.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.
.. versionchanged:: 0.8.2 The :meth:`.Select.correlate_except`
method was improved to fully prevent FROM clauses specified here
from being omitted from the immediate FROM clause of this
:class:`.Select`.
If ``None`` is passed, the :class:`.Select` object will correlate
all of its FROM entries.
.. versionchanged:: 0.8.2 calling ``correlate_except(None)`` will
correctly auto-correlate all FROM clauses.
:param \*fromclauses: a list of one or more :class:`.FromClause`
constructs, or other compatible constructs (i.e. ORM-mapped
classes) to become part of the correlate-exception collection.
.. seealso::
:meth:`.Select.correlate`
:ref:`correlated_subqueries`
Fr"Ncss|]}t|<00>VqdS)N)r2)r]r<>r0r0r1r<> sz*Select.correlate_except.<locals>.<genexpr>)r2rar<>r<>)r9r{r0r0r1<00>correlate_except<70> s
#  zSelect.correlate_exceptcCs5d|_t|j<00>jdd<00>|D<><00>|_dS)z<>append the given correlation expression to this select()
construct.
This is an **in-place** mutation method; the
:meth:`~.Select.correlate` method is preferred, as it provides
standard :term:`method chaining`.
Fcss|]}t|<00>VqdS)N)r2)r]r<>r0r0r1r<> sz,Select.append_correlation.<locals>.<genexpr>N)r2r<>rcr<>)r9rir0r0r1<00>append_correlation s
zSelect.append_correlationcCsT|j<00>t|<00>}t|t<00>r=|jdtj<00>}n|j|g|_dS)a
append the given column expression to the columns clause of this
select() construct.
This is an **in-place** mutation method; the
:meth:`~.Select.column` method is preferred, as it provides standard
:term:`method chaining`.
r<>N)r<>r r)rr<>r$rRrQ)r9r<>r0r0r1r s
 zSelect.append_columncCs#t|<00>}|j|f|_dS)aappend the given columns clause prefix expression to this select()
construct.
This is an **in-place** mutation method; the
:meth:`~.Select.prefix_with` method is preferred, as it provides
standard :term:`method chaining`.
N)r r`)r9rHr0r0r1<00> append_prefix* s zSelect.append_prefixcCs,|j<00>ttj|j<00>|<00>|_dS)aJappend the given expression to this select() construct's WHERE
criterion.
The expression will be joined to existing WHERE criterion via AND.
This is an **in-place** mutation method; the
:meth:`~.Select.where` method is preferred, as it provides standard
:term:`method chaining`.
N)r<>rr<00>_ifnonerS)r9rsr0r0r1rv6 s
zSelect.append_whereclausecCs,|j<00>ttj|j<00>|<00>|_dS)aMappend the given expression to this select() construct's HAVING
criterion.
The expression will be joined to existing HAVING criterion via AND.
This is an **in-place** mutation method; the
:meth:`~.Select.having` method is preferred, as it provides standard
:term:`method chaining`.
N)r<>rrrrT)r9rVr0r0r1rxF s
zSelect.append_havingcCs2|j<00>t|<00>}|jj|g<00>|_dS)a append the given FromClause expression to this select() construct's
FROM clause.
This is an **in-place** mutation method; the
:meth:`~.Select.select_from` method is preferred, as it provides
standard :term:`method chaining`.
N)r<>r2rNr<>)r9rir0r0r1ryT s
 zSelect.append_fromcst|jrMt<00><00><00>fdd<00><00><00>fdd<00>tjt|j<00><00>D<>Sdd<00>tjt|j<00><00>D<>SdS)Ncs[|jdks|j r#d|fS|j}|<00>krD|j}n <00>j|<00>||fS)N)r<>Z_render_label_in_columns_clause<73>
anon_labelr<EFBFBD>)r<>rD)<01>namesr0r1<00> name_for_colf s
    z0Select._columns_plus_names.<locals>.name_for_colcsg|]}<00>|<00><00>qSr0r0)r]r<>)r<>r0r1r_r s z.Select._columns_plus_names.<locals>.<listcomp>cSsg|]}d|f<00>qS)Nr0)r]r<>r0r0r1r_x s )r<>r<>r Z unique_listrrQ)r9r0)r<>r<>r1<00>_columns_plus_namesa s    zSelect._columns_plus_namesc Cs<>x<>|jD]<5D>\}}t|d<00>s+q
n|dkr@d}nB|jr||j}|dk r<>||jkr<>|j}q<>nd}|j|d|d|dd<00>q
WdS)Nr<4E>r<>rD<00>name_is_truncatableT)r<>rBr<>rDr<>r<>r<>)r9rDr<>r<>r0r0r1r<>} s    z"Select._populate_column_collectionc Cs<>x<>|jD]<5D>}|j|<00>}|dk r
||jkr<>|jr<>|jrU|jn|j}||jkr<>|j|d|jr<>|j ndd|jr<>|jnddd<00>SndSq
WdS)NrDr<>r<>T)
r]r<>rnr<>r<>rDr<>r<>r<>r<>)r9r<>riruZ our_labelr0r0r1r<><00> s 
zSelect._refresh_for_new_columncCst|t<00>r|St|<00>S)a+return a 'grouping' construct as per the ClauseElement
specification.
This produces an element that can be embedded in an expression. Note
that this method is called automatically as needed when constructing
expressions and should not require explicit use.
)r)r.r<>)r9r<>r0r0r1r<><00> s zSelect.self_groupcKstj|||<00>S)zSreturn a SQL UNION of this select() construct against the given
selectable.)r.r9)r9r~rNr0r0r1r<><00> sz Select.unioncKstj|||<00>S)zareturn a SQL UNION ALL of this select() construct against the given
selectable.
)r.r;)r9r~rNr0r0r1r<><00> szSelect.union_allcKstj|||<00>S)zTreturn a SQL EXCEPT of this select() construct against the given
selectable.)r.r<)r9r~rNr0r0r1<00>except_<74> szSelect.except_cKstj|||<00>S)zbreturn a SQL EXCEPT ALL of this select() construct against the
given selectable.
)r.r>)r9r~rNr0r0r1<00>
except_all<EFBFBD> szSelect.except_allcKstj|||<00>S)zareturn a SQL INTERSECT of this select() construct against the given
selectable.
)r.r?)r9r~rNr0r0r1r<><00> szSelect.intersectcKstj|||<00>S)zereturn a SQL INTERSECT ALL of this select() construct against the
given selectable.
)r.rA)r9r~rNr0r0r1<00> intersect_all<6C> szSelect.intersect_allcCs||jr|jS|j}|sRxV|jD]"}|j}|r)||_|Sq)Wn&t|<00>dj}|rx||_|SdS)Nr")rr]rQr<>rn)r9rYr<>rIr0r0r1r<><00> s      z Select.bindcCs ||_dS)N)r)r9r<>r0r0r1rJ<00> szSelect._set_bind)@r;r<r=rRrSr`rfr Z immutabledictrlrkrLrWrcrar5r<>r<>r<>r>r]rdrBrYrjrrgre<00>methodrmrnr,r|r
r<>r<>r<>r<>r<>rtrwrVrUrzr<>r|r}rr~rvrxryr<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>rJr0r0)r<>r1rK<00>s<>   <0F>F '  -
 a "?*               rKc@s^eZdZgZdZdd<00>Zedd<00><00>ZeZe dd<00><00>Z
dd <00>Z d
S) rTcCs||_|j<00>|_dS)N)r/rBre)r9r/r0r0r1r<><00> s zScalarSelect.__init__cCstjd<00><00>dS)NzcScalar Select expression has no columns; use this object directly within a column-level expression.)r!rX)r9r0r0r1ro<00> szScalarSelect.columnscCs|jj|<00>|_dS)zjApply a WHERE clause to the SELECT statement referred to
by this :class:`.ScalarSelect`.
N)r/rw)r9r<>r0r0r1rw<00> szScalarSelect.wherecKs|S)Nr0)r9rNr0r0r1r<> szScalarSelect.self_groupN) r;r<r=rr<>r<>r>ror<>rrwr<>r0r0r0r1r<00> s  rc@speZdZdZejZgZdd<00>Zddd<00>Zdd<00>Z d d
<00>Z
d d <00>Z d d<00>Z dS)<0F>Existsz%Represent an ``EXISTS`` clause.
c Os<>|r,t|dttf<00>r,|d}n6|sGtd<00>gf}nt||<00>j<00>j<00>}tj||dt j
dt j dd<00>dS)aConstruct a new :class:`.Exists` against an existing
:class:`.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 = exists(s)
# 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)
r"rfr<>r@Zwraps_column_expressionTN) r)r5rrrKr<>r<>rr<>r$<00>existsrZ BOOLEANTYPE)r9rMrNrr0r0r1r<> s  zExists.__init__NcKst|g||<00>S)N)rK)r9rsrtr0r0r1r6( sz Exists.selectcGs+|j<00>}|jj|<00>j<00>|_|S)N)r
r/r<>r<>)r9rirIr0r0r1r<>+ s zExists.correlatecGs+|j<00>}|jj|<00>j<00>|_|S)N)r
r/r|r<>)r9rirIr0r0r1r|0 s zExists.correlate_exceptcCs+|j<00>}|jj|<00>j<00>|_|S)z<>return a new :class:`.Exists` construct, applying the given
expression to the :meth:`.Select.select_from` method of the select
statement contained.
)r
r/rzr<>)r9rHrIr0r0r1rz5 s zExists.select_fromcCs+|j<00>}|jj|<00>j<00>|_|S)z<>return a new exists() construct with the given expression added to
its WHERE clause, joined to the existing clause via AND, if any.
)r
r/rwr<>)r9rHrIr0r0r1rw? s z Exists.where) r;r<r=rRrrSrr<>r6r<>r|rzrwr0r0r0r1r<> s     
r<EFBFBD>c@syeZdZdZdZdZdd<00>Zedd<00><00>Ze dd <00><00>Z
d
d <00>Z e d d <00>Z dd<00>ZdS)<11>
TextAsFroma<EFBFBD>Wrap a :class:`.TextClause` construct within a :class:`.SelectBase`
interface.
This allows the :class:`.TextClause` object to gain a ``.c`` collection
and other FROM-like capabilities such as :meth:`.FromClause.alias`,
:meth:`.SelectBase.cte`, etc.
The :class:`.TextAsFrom` construct is produced via the
:meth:`.TextClause.columns` method - see that method for details.
.. versionadded:: 0.9.0
.. seealso::
:func:`.text`
:meth:`.TextClause.columns`
Z text_as_fromTcCs||_||_dS)N)r/<00> column_args)r9rhror0r0r1r<>a s zTextAsFrom.__init__cCs
|jjS)N)r/r)r9r0r0r1re szTextAsFrom._bindcOs|jj||<00>|_dS)N)r/<00>
bindparams)r9ZbindsZbind_as_valuesr0r0r1r<>i szTextAsFrom.bindparamscCs%x|jD]}|j|<00>q
WdS)N)r<>r<>)r9r<>r0r0r1r<>m sz&TextAsFrom._populate_column_collectioncKs#|j<00>||j|<00>|_dS)N)r<>r/)r9r<>rZr0r0r1r<>q s
zTextAsFrom._copy_internalscCs|jdjS)Nr")r<>re)r9r0r0r1rBu szTextAsFrom._scalar_typeN)r;r<r=rRrSr<>r<>r>rrr<>r<>r
r<>rBr0r0r0r1r<>I s   r<>c@seZdZdd<00>ZdS)<04>AnnotatedFromClausecCs|jtj|||<00>dS)N)r<>r%r<>)r9r/r<>r0r0r1r<>z szAnnotatedFromClause.__init__N)r;r<r=r<>r0r0r0r1r<>y s r<>)FrRr<>rrrrrrrr r
r r r rrrrrrrr<00>baserrrrrrrr<>rrr r!r<>r#r$r<>Z
annotationr%r<>Zsqlalchemy.sql.visitorsr&r2r7r8rFrJrOrLrQ<00>objectrTrcrhrvr3r<>r<>r<>rr5rr.rKrr<>r<>r<>r0r0r0r1<00><module> s\:R4       + %$<16><00><16><00>_=4<19>E<19><16><16><1C><00><00><00>AE0