֚:dZddlmZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z dd l mZdd l mZdd l mZdd l mZdd lmZddlmZddlmZddlmZddlmZddlmZdZdZdZddZddZddZdZej GddeZ!Gddej"e!Z#Gd d!e#Z$Gd"d#e!Z%Gd$d%ee!Z&Gd&d'e#Z'Gd(d)e#Z(Gd*d+e#Z)Gd,d-e!Z*Gd.d/e*e#Z+e+j,Z,e+j-Z-Gd0d1e*e#Z.Gd2d3e#Z/dd4Z0Gd5d6e#Z1Gd7d8e#Z2Gd9d:e#Z3Gd;de#Z5Gd?d@e#Z6GdAdBe6Z7GdCdDe6Z8GdEdFe#Z9GdGdHe#Z:GdIdJe9Z;GdKdLe#Z<ej=dMZ>ej=dNZ?GdOdPe#Z@GdQdRe#ZAGdSdTe#ZBGdUdVe#ZCGdWdXee#ZDGdYdZe#ZEGd[d\ee!ZFGd]d^eFZGGd_d`eFZHGdadbeFZIGdcddejJejKZLGdedfeLZMGdgdheMZNej=diZO eMZPGdjdkeMZQdlZRdmZSdnZTdoZUdpZVdqZWejXdrdsZYdtZZduZ[dvZ\dwZ]dxZ^dyZ_dzZ`d{Zadd|Zbd}Zcd~ZdejeddfdZfdZgdZhdZidZjddZkejldejmZndZodZpdZqddZrGdde ZsdS)zCore SQL expression elements, including :class:`_expression.ClauseElement`, :class:`_expression.ColumnElement`, and derived classes. )unicode_literalsN) operators)type_api Annotated) _generative) Executable) Immutable)NO_ARG)PARSE_AUTOCOMMIT)cloned_traverse)traverse) Visitable)exc) inspection)utilc *|SN_clone)elementkws /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/sqlalchemy/sql/elements.pyrr$s >>  c:tj|d|d|dS)Nz.. warning:: The z argument to z can be passed as a Python string argument, which will be treated as **trusted SQL text** and rendered as given. **DO NOT PASS UNTRUSTED INPUT TO THIS PARAMETER**.)radd_parameter_text) paramnamemeth_rst param_rsts r_document_text_coercionr"(s0  "  99hhh    rc~t|}t|t|tj|jS)aReturn the clause ``expression COLLATE collation``. e.g.:: collate(mycolumn, 'utf8_bin') produces:: mycolumn COLLATE utf8_bin The collation expression is also quoted if it is a case sensitive identifier, e.g. contains uppercase characters. .. versionchanged:: 1.2 quoting is automatically applied to COLLATE expressions if they are case sensitive. type_)_literal_as_bindsBinaryExpressionCollationClausercollatetype) expression collationexprs rr)r)6s>& Z ( (D  oi(()*;49   rFcPt|}||||S)axProduce a ``BETWEEN`` predicate clause. E.g.:: from sqlalchemy import between stmt = select([users_table]).where(between(users_table.c.id, 5, 7)) Would produce SQL resembling:: SELECT id, name FROM user WHERE id BETWEEN :id_1 AND :id_2 The :func:`.between` function is a standalone version of the :meth:`_expression.ColumnElement.between` method available on all SQL expressions, as in:: stmt = select([users_table]).where(users_table.c.id.between(5, 7)) All arguments passed to :func:`.between`, including the left side column expression, are coerced from Python scalar values if a the value is not a :class:`_expression.ColumnElement` subclass. For example, three fixed values can be compared as in:: print(between(5, 3, 7)) Which would produce:: :param_1 BETWEEN :param_2 AND :param_3 :param expr: a column expression, typically a :class:`_expression.ColumnElement` instance or alternatively a Python scalar expression to be coerced into a column expression, serving as the left side of the ``BETWEEN`` expression. :param lower_bound: a column or Python scalar expression serving as the lower bound of the right side of the ``BETWEEN`` expression. :param upper_bound: a column or Python scalar expression serving as the upper bound of the right side of the ``BETWEEN`` expression. :param symmetric: if True, will render " BETWEEN SYMMETRIC ". Note that not all databases support this syntax. .. versionadded:: 0.9.5 .. seealso:: :meth:`_expression.ColumnElement.between` ) symmetric)r&between)r- lower_bound upper_boundr/s rr0r0Os*h T " "D << [I< F FFrc(td||dS)aReturn a literal clause, bound to a bind parameter. Literal clauses are created automatically when non- :class:`_expression.ClauseElement` objects (such as strings, ints, dates, etc.) are used in a comparison operation with a :class:`_expression.ColumnElement` subclass, such as a :class:`~sqlalchemy.schema.Column` object. Use this function to force the generation of a literal clause, which will be created as a :class:`BindParameter` with a bound value. :param value: the value to be bound. Can be any Python object supported by the underlying DB-API, or is translatable via the given type argument. :param type\_: an optional :class:`~sqlalchemy.types.TypeEngine` which will provide bind-parameter translation for this literal. NTr%unique BindParameter)valuer%s rliteralr9s& uE$ ? ? ??rc*t|d|ddS)awCreate an 'OUT' parameter for usage in functions (stored procedures), for databases which support them. The ``outparam`` can be used like a regular function parameter. The "output" value will be available from the :class:`~sqlalchemy.engine.ResultProxy` object via its ``out_parameters`` attribute, which returns a dictionary containing the values. NFT)r%r5 isoutparamr6)keyr%s routparamr=s d%$ O O OOrcDtjt|S)zReturn a negation of the given clause, i.e. ``NOT(clause)``. The ``~`` operator is also overloaded on all :class:`_expression.ColumnElement` subclasses to produce the same result. )rinvr&clauses rnot_rBs =*622 3 33rceZdZdZdZiZdZgZdZdZ dZ dZ dZ dZ dZdZedZejdZd Zd Zd Zd"d Zd ZdZdZdZdZefdZdZd#dZ ej!dd$dZ"dZ#dZ$ej%dddZ&ej%dddZ'dZ(dZ)d Z*e*Z+d!Z,dS)% ClauseElementzSBase class for elements of a programmatically constructed SQL expression. rAFNTc |j|j}|j|_tj|tj|||_ |S)zCreate a shallow copy of this ClauseElement. This method may be used by a generative API. Its also used as part of the "deep" copy afforded by a traversal that combines the _copy_internals() method. ) __class____new____dict__copyrD _cloned_set_reset ColumnElement comparator _is_clone_ofselfcs rrzClauseElement._clonesl N " "4> 2 2]'')) !((+++ ''***rc|jS)a.return the 'constructor' for this ClauseElement. This is for the purposes for creating a new object of this type. Usually, its just the element's __class__. However, the "Annotated" version of the object overrides to return the class of its proxied element. rFrPs r _constructorzClauseElement._constructors ~rcptj}|}||||j}||S)aReturn the set consisting all cloned ancestors of this ClauseElement. Includes this ClauseElement. This accessor tends to be used for FromClause objects to identify 'equivalent' FROM clauses, regardless of transformative operations. )r column_setaddrN)rPsfs rrJzClauseElement._cloned_setsA O   m EE!HHHAmrcd|j}|dd|S)NrN)rHrIpop)rPds r __getstate__zClauseElement.__getstate__s. M    nd###rc"t||S)zgReturn a copy of this ClauseElement with annotations updated by the given dictionary. rrPvaluess r _annotatezClauseElement._annotate v&&&rc"t||S)zhReturn a copy of this ClauseElement with annotations replaced by the given dictionary. rr`s r_with_annotationszClauseElement._with_annotationsrcrc2|r|S|S)zReturn a copy of this :class:`_expression.ClauseElement` with annotations removed. :param values: optional tuple of individual values to remove. r)rPraclones r _deannotatezClauseElement._deannotates#  ;;== Krcf|jr||||Stj|r)supports_execution_execute_clauseelementrObjectNotExecutableError)rP connection multiparamsparamss r_execute_on_connectionz$ClauseElement._execute_on_connection(s6  " 544T;OO O.t44 4rc0|d||S)aReturn a copy with :func:`_expression.bindparam` elements replaced. Same functionality as :meth:`_expression.ClauseElement.params`, except adds `unique=True` to affected bind parameters so that multiple statements can be used. T_paramsrP optionaldictkwargss r unique_paramszClauseElement.unique_params.s||D,777rc0|d||S)aReturn a copy with :func:`_expression.bindparam` elements replaced. Returns a copy of this ClauseElement with :func:`_expression.bindparam` elements replaced with values taken from the given dictionary:: >>> clause = column('x') + bindparam('foo') >>> print(clause.compile().params) {'foo':None} >>> print(clause.params({'foo':7}).compile().params) {'foo':7} Frrrts rrozClauseElement.params:s||E<888rct|dkr|dn't|dkrtjdfd}t |id|iS)Nrrz9params() takes zero or one positional dictionary argumentc||jvr|j|_d|_r|dSdSNF)r<r8required_convert_to_unique)bindrvr5s rvisit_bindparamz.ClauseElement._params..visit_bindparamSsOx6!!#DH- %  *''))))) * *r bindparam)lenupdater ArgumentErrorr)rPr5rurvrs ` ` rrszClauseElement._paramsKs |   ! ! MM,q/ * * * *    " "#K  * * * * * *tR+)GHHHrc ||uS)aCompare this :class:`_expression.ClauseElement` to the given :class:`_expression.ClauseElement`. Subclasses should override the default behavior, which is a straight identity comparison. \**kw are arguments consumed by subclass ``compare()`` methods and may be used to modify the criteria for comparison (see :class:`_expression.ColumnElement`). rPotherrs rcomparezClauseElement.compare\su}rc dS)atReassign internal elements to be clones of themselves. Called during a copy-and-traverse operation on newly shallow-copied elements to create a deep copy. The given clone function should be used, which may be applying additional transformations to the element (i.e. replacement traversal, cloned traversal, annotations). NrrPrgrs r_copy_internalszClauseElement._copy_internalsjs  rc gS)aReturn immediate child elements of this :class:`_expression.ClauseElement`. This is used for visit traversal. \**kwargs may contain flags that change the collection that is returned, for example to return a subset of items in order to cut down on larger traversals, or to return child items from a different context (such as schema-level collections instead of clause-level). rrPrvs r get_childrenzClauseElement.get_childrenws  rc|S)aApply a 'grouping' to this :class:`_expression.ClauseElement`. This method is overridden by subclasses to return a "grouping" construct, i.e. parenthesis. In particular it's used by "binary" expressions to provide a grouping around themselves when placed into a larger expression, as well as by :func:`_expression.select` constructs when placed into the FROM clause of another :func:`_expression.select`. (Note that subqueries should be normally created using the :meth:`_expression.Select.alias` method, as many platforms require nested SELECT statements to be named). As expressions are composed together, the application of :meth:`self_group` is automatic - end-user code should never need to use this method directly. Note that SQLAlchemy's clause constructs take operator precedence into account - so parenthesis might not be needed, for example, in an expression like ``x OR (y AND z)`` - AND takes precedence over OR. The base :meth:`self_group` method of :class:`_expression.ClauseElement` just returns self. rrPagainsts r self_groupzClauseElement.self_groups 2 rzsqlalchemy.engine.defaultc |s9|r|j}n/|jr|jj}|j}n|}|j|fd|i|S)a+ Compile this SQL expression. The return value is a :class:`~.Compiled` object. Calling ``str()`` or ``unicode()`` on the returned value will yield a string representation of the result. The :class:`~.Compiled` object also can return a dictionary of bind parameter names and values using the ``params`` accessor. :param bind: An ``Engine`` or ``Connection`` from which a ``Compiled`` will be acquired. This argument takes precedence over this :class:`_expression.ClauseElement`'s bound engine, if any. :param column_keys: Used for INSERT and UPDATE statements, a list of column names which should be present in the VALUES clause of the compiled statement. If ``None``, all columns from the target table object are rendered. :param dialect: A ``Dialect`` instance from which a ``Compiled`` will be acquired. This argument takes precedence over the `bind` argument as well as this :class:`_expression.ClauseElement` 's bound engine, if any. :param inline: Used for INSERT statements, for a dialect which does not support inline retrieval of newly generated primary key columns, will force the expression used to create the new primary key value to be rendered inline within the INSERT statement's VALUES clause. This typically refers to Sequence execution but may also refer to any server-side default generation function associated with a primary key `Column`. :param compile_kwargs: optional dictionary of additional parameters that will be passed through to the compiler within all "visit" methods. This allows any custom flag to be passed through to a custom compilation construct, for example. It is also used for the case of passing the ``literal_binds`` flag through:: from sqlalchemy.sql import table, column, select t = table('t', column('x')) s = select([t]).where(t.c.x == 5) print(s.compile(compile_kwargs={"literal_binds": True})) .. versionadded:: 0.9.0 .. seealso:: :ref:`faq_sql_expression_string` r~)dialectr~StrCompileDialect _compiler)rPdefaultr~rrs rcompilezClauseElement.compileskp 6 6, 6)+y!3355t~g77D7B777rc |j||fi|S)zNReturn a compiler appropriate for this ClauseElement, given a Dialect.)statement_compiler)rPrrs rrzClauseElement._compilers!*w)'4>>2>>>rctjr!t|St |ddSNasciibackslashreplace)rpy3kstrrunicodeencoderTs r__str__zClauseElement.__str__sP 9 t||~~&& &4<<>>**11+ r0.9zThe :meth:`_expression.ClauseElement.__and__` method is deprecated and will be removed in a future release. Conjunctions should only be used from a :class:`_expression.ColumnElement` subclass, e.g. :meth:`_expression.ColumnElement.__and__`.c"t||S)z!'and' at the ClauseElement level.and_rPrs r__and__zClauseElement.__and__sD%   rzThe :meth:`_expression.ClauseElement.__or__` method is deprecated and will be removed in a future release. Conjunctions should only be used from a :class:`_expression.ColumnElement` subclass, e.g. :meth:`_expression.ColumnElement.__or__`.c"t||S)z 'or' at the ClauseElement level.)or_rs r__or__zClauseElement.__or__s4rcXt|dr|jS|S)Nnegation_clause)hasattrr_negaterTs r __invert__zClauseElement.__invert__ s, 4* + + "' '<<>> !rcvt|tjtjdS)Nr)operatornegate)UnaryExpressionrrr?rTs rrzClauseElement._negates4 OOIMO 2 2]    rc td)N+Boolean value of this clause is not defined) TypeErrorrTs r__bool__zClauseElement.__bool__sEFFFrc|j}|t|Sd|j|jjt ||fzS)Nz<%s.%s at 0x%x; %s>) descriptionobject__repr__ __module__rF__name__id)rPfriendlys rrzClauseElement.__repr__sM#  ??4(( (('4 , rr{rNN)-rr __qualname____doc____visit_name__ _annotationsrj _from_objectsr~rN is_selectableis_clause_elementr_order_by_label_element_is_from_containerrpropertyrUrmemoized_propertyrJr^rbrerhrprwrorsrrrr dependenciesrrr deprecatedrrrrr __nonzero__rrrrrDrDsk NLM DLMK",  X  , ''''''$555 8 8 8999"III"   %+        6T233?8?8?843?8B??? T_  5!!!T_  4   """    GGGK     rrDc|eZdZdZdZdZgZdZdZ dZ dZ dZ dZ dZ dZdZddZfdZejd Zejd Zd Zd Zd ZddZedZedZejdZejdZdZdZ dZ! ddZ"ddZ#dZ$dZ%ejdZ&xZ'S)rLa+Represent a column-oriented SQL expression suitable for usage in the "columns" clause, WHERE clause etc. of a statement. While the most familiar kind of :class:`_expression.ColumnElement` is the :class:`_schema.Column` object, :class:`_expression.ColumnElement` serves as the basis for any unit that may be present in a SQL expression, including the expressions themselves, SQL functions, bound parameters, literal expressions, keywords such as ``NULL``, etc. :class:`_expression.ColumnElement` is the ultimate base class for all such elements. A wide variety of SQLAlchemy Core functions work at the SQL expression level, and are intended to accept instances of :class:`_expression.ColumnElement` as arguments. These functions will typically document that they accept a "SQL expression" as an argument. What this means in terms of SQLAlchemy usually refers to an input which is either already in the form of a :class:`_expression.ColumnElement` object, or a value which can be **coerced** into one. The coercion rules followed by most, but not all, SQLAlchemy Core functions with regards to SQL expressions are as follows: * a literal Python value, such as a string, integer or floating point value, boolean, datetime, ``Decimal`` object, or virtually any other Python object, will be coerced into a "literal bound value". This generally means that a :func:`.bindparam` will be produced featuring the given value embedded into the construct; the resulting :class:`.BindParameter` object is an instance of :class:`_expression.ColumnElement`. The Python value will ultimately be sent to the DBAPI at execution time as a parameterized argument to the ``execute()`` or ``executemany()`` methods, after SQLAlchemy type-specific converters (e.g. those provided by any associated :class:`.TypeEngine` objects) are applied to the value. * any special object value, typically ORM-level constructs, which feature a method called ``__clause_element__()``. The Core expression system looks for this method when an object of otherwise unknown type is passed to a function that is looking to coerce the argument into a :class:`_expression.ColumnElement` expression. The ``__clause_element__()`` method, if present, should return a :class:`_expression.ColumnElement` instance. The primary use of ``__clause_element__()`` within SQLAlchemy is that of class-bound attributes on ORM-mapped classes; a ``User`` class which contains a mapped attribute named ``.name`` will have a method ``User.name.__clause_element__()`` which when invoked returns the :class:`_schema.Column` called ``name`` associated with the mapped table. * The Python ``None`` value is typically interpreted as ``NULL``, which in SQLAlchemy Core produces an instance of :func:`.null`. A :class:`_expression.ColumnElement` provides the ability to generate new :class:`_expression.ColumnElement` objects using Python expressions. This means that Python operators such as ``==``, ``!=`` and ``<`` are overloaded to mimic SQL operations, and allow the instantiation of further :class:`_expression.ColumnElement` instances which are composed from other, more fundamental :class:`_expression.ColumnElement` objects. For example, two :class:`.ColumnClause` objects can be added together with the addition operator ``+`` to produce a :class:`.BinaryExpression`. Both :class:`.ColumnClause` and :class:`.BinaryExpression` are subclasses of :class:`_expression.ColumnElement`:: >>> from sqlalchemy.sql import column >>> column('a') + column('b') >>> print(column('a') + column('b')) a + b .. seealso:: :class:`_schema.Column` :func:`_expression.column` column_elementFrNTc&|tjtjtjfvrB|jjt jjur%t|tj tj S|tj tj fvrt|S|Sr)rrr_asboolr*_type_affinityr BOOLEANTYPE AsBooleanistrueisfalseany_opall_opGroupingrs rrzColumnElement.self_groupsp   y7HI I I (H,@,OOOT9#3Y5FGG G )9+;< < <D>> !Krc|jjtjjur%t |t jt jStt| Sr) r*rrrrrrrsuperrLrrPrFs rrzColumnElement._negatesM 9 #x';'J J JT9#4i6FGG G--5577 7rctjSrrNULLTYPErTs rr*zColumnElement.type   rc |jj}||S#t$r6}tjt d|jz|Yd}~dSd}~wwxYw)NzOObject %r associated with '.type' attribute is not a TypeEngine class or objectreplace_context)r*comparator_factoryAttributeErrorrraise_r)rPrerrs rrMzColumnElement.comparators ,!%!= &%d++ +    K:<@IF!$            s  A+AAc  t|j|S#t$r`}tjtdt |jdt |jjd||Yd}~dSd}~wwxYw)NzNeither z object nor z object has an attribute r)getattrrMrrrr*r)rPr<rs r __getattr__zColumnElement.__getattr__s 4?C00 0    KT +++T_--666 !$           s BAA<<Bc$||jg|Ri|SrrMrPoprrvs roperatezColumnElement.operates$r$/4E444V444rc |||jfi|Srrrs rreverse_operatezColumnElement.reverse_operatesr%33F333rc6td||||jdS)NT)_compared_to_operatorr%_compared_to_typer5)r7r*rProbjr%s r _bind_paramzColumnElement._bind_params-  "*"i     rc|S)z^Return a column expression. Part of the inspection interface; returns self. rrTs rr+zColumnElement.expression s  rc|fSrrrTs r_select_iterablezColumnElement._select_iterable wrcHtjd|jDS)Nc3(K|] }|j |VdSr)_proxies.0rQs r z-ColumnElement.base_columns..s)KKQ KqKKKKKKr)rrW proxy_setrTs r base_columnszColumnElement.base_columnss#KK$.KKKKKKrcxtj|g}|jD]}||j|Sr)rrWrrrrPrYrQs rrzColumnElement.proxy_sets@ OTF # # " "A HHQ[ ! ! ! !rctj|g}|jD])}||*|S)zAn 'uncached' version of proxy set. This is so that we can read annotations from the list of columns without breaking the caching of the above proxy_set. )rrWrr_uncached_proxy_setr s rr z!ColumnElement._uncached_proxy_set!sL OTF # # . .A HHQ**,, - - - -rcZt|j|jS)zReturn True if the given :class:`_expression.ColumnElement` has a common ancestor to this :class:`_expression.ColumnElement`.)boolr intersection)rP othercolumns rshares_lineagezColumnElement.shares_lineage-s%DN// 0EFFGGGrcbt|dot|do|j|jkS)zhReturn True if the given column element compares to this one when targeting within a result row.name)rrrs r_compare_name_for_resultz&ColumnElement._compare_name_for_result3s9 E6 " " (f%% ( di' rc r|C|j}|jr|j}n/ t|}n#tj$r |j}YnwxYw|}t |rt |n|t|dd|}|g|_|j $|j j ||_ ||j |<|S)zCreate a new :class:`_expression.ColumnElement` representing this :class:`_expression.ColumnElement` as it appears in the select list of a descending selectable. Nr*)r% _selectable) anon_labelr<rrUnsupportedCompilationError ColumnClause _as_truncatedrrrNcolumnsget_columns)rP selectablername_is_truncatablerr<cos r _make_proxyzColumnElement._make_proxy=s <?Dx *h*d))CC6***/CCC*C #6 @M$   D$--"    f  " .(5=AA#FFBO#% C  s*AAc |f}|r||vr|||}|D]?}|r||rdSt|t|krdS@dS)aCompare this ColumnElement to another. Special arguments understood: :param use_proxies: when True, consider two columns that share a common base column as equivalent (i.e. shares_lineage()) :param equivalents: a dictionary of columns as keys mapped to sets of columns. If the given "other" column is present in this dictionary, if any of the columns in the corresponding set() pass the comparison test, the result is True. This is used to expand the comparison to other columns that may be known to be equivalent to this one via foreign key or other criterion. TF)unionrhash)rPr use_proxies equivalentsr to_compareoths rrzColumnElement.compare^s X  >5K//$U+11*==J  C t22377 ttcd4jj((tt)5rc"t||S)a<Produce a type cast, i.e. ``CAST( AS )``. This is a shortcut to the :func:`_expression.cast` function. .. seealso:: :ref:`coretutorial_casts` :func:`_expression.cast` :func:`_expression.type_coerce` .. versionadded:: 1.0.7 )CastrPr%s rcastzColumnElement.castzs D%   rc.t|||jS)zProduce a column label, i.e. `` AS ``. This is a shortcut to the :func:`_expression.label` function. If 'name' is ``None``, an anonymous label name will be generated. )Labelr*)rPrs rlabelzColumnElement.labelsT4+++rc |j|j}|jtdt|t|ddfzS)a Provides a constant 'anonymous label' for this ColumnElement. This is a label() expression which will be named at compile time. The same label() is returned each time ``anon_label`` is called so that expressions can reference ``anon_label`` multiple times, producing the same label name at compile time. The compiler uses this function automatically at compile time for expressions that are known to be 'unnamed' like binary expressions and function calls. N %%(%d %s)sranon)rN_anonymous_labelrrrTs rrzColumnElement.anon_labelsS+$D+ BtHHgdFF&C&CD D   rrr{)FN)(rrrrr primary_key foreign_keysr_labelr< _key_label_render_label_in_columns_clause_resolve_label_allow_label_resolve_is_implicitly_boolean _alt_namesrrrrr*rMrrrrrr+rrrr rrr rr+r.r __classcell__rSs@rrLrL(sUOOb&NKLH F  CJ '+#N  #J    88888  !!!  , , , 555444    XX LLL    HHH    :?B8!!!$,,,        rrLc eZdZdZdZdZdZeddeddddddf dZdZ dZ e d Z d Z d Zd Zd ZdZdZdS)r7aRepresent a "bound expression". :class:`.BindParameter` is invoked explicitly using the :func:`.bindparam` function, as in:: from sqlalchemy import bindparam stmt = select([users_table]).\ where(users_table.c.name == bindparam('username')) Detailed discussion of how :class:`.BindParameter` is used is at :func:`.bindparam`. .. seealso:: :func:`.bindparam` rFrNc t|tr|j}|j}|tur |tuo|du}|turd}|t ||}|rRt dt||)tj dd| dndfz|_n&|pt dt|z|_|j|_ |pd|_ ||_ ||_||_| |_||_||_|:| | | ||_dSt)j||_dSt|tr||_dS||_dS)az$Produce a "bound expression". The return value is an instance of :class:`.BindParameter`; this is a :class:`_expression.ColumnElement` subclass which represents a so-called "placeholder" value in a SQL expression, the value of which is supplied at the point at which the statement in executed against a database connection. In SQLAlchemy, the :func:`.bindparam` construct has the ability to carry along the actual value that will be ultimately used at expression time. In this way, it serves not just as a "placeholder" for eventual population, but also as a means of representing so-called "unsafe" values which should not be rendered directly in a SQL statement, but rather should be passed along to the :term:`DBAPI` as values which need to be correctly escaped and potentially handled for type-safety. When using :func:`.bindparam` explicitly, the use case is typically one of traditional deferment of parameters; the :func:`.bindparam` construct accepts a name which can then be referred to at execution time:: from sqlalchemy import bindparam stmt = select([users_table]).\ where(users_table.c.name == bindparam('username')) The above statement, when rendered, will produce SQL similar to:: SELECT id, name FROM user WHERE name = :username In order to populate the value of ``:username`` above, the value would typically be applied at execution time to a method like :meth:`_engine.Connection.execute`:: result = connection.execute(stmt, username='wendy') Explicit use of :func:`.bindparam` is also common when producing UPDATE or DELETE statements that are to be invoked multiple times, where the WHERE criterion of the statement is to change on each invocation, such as:: stmt = (users_table.update(). where(user_table.c.name == bindparam('username')). values(fullname=bindparam('fullname')) ) connection.execute( stmt, [{"username": "wendy", "fullname": "Wendy Smith"}, {"username": "jack", "fullname": "Jack Jones"}, ] ) SQLAlchemy's Core expression system makes wide use of :func:`.bindparam` in an implicit sense. It is typical that Python literal values passed to virtually all SQL expression functions are coerced into fixed :func:`.bindparam` constructs. For example, given a comparison operation such as:: expr = users_table.c.name == 'Wendy' The above expression will produce a :class:`.BinaryExpression` construct, where the left side is the :class:`_schema.Column` object representing the ``name`` column, and the right side is a :class:`.BindParameter` representing the literal value:: print(repr(expr.right)) BindParameter('%(4327771088 name)s', 'Wendy', type_=String()) The expression above will render SQL such as:: user.name = :name_1 Where the ``:name_1`` parameter name is an anonymous name. The actual string ``Wendy`` is not in the rendered string, but is carried along where it is later used within statement execution. If we invoke a statement like the following:: stmt = select([users_table]).where(users_table.c.name == 'Wendy') result = connection.execute(stmt) We would see SQL logging output as:: SELECT "user".id, "user".name FROM "user" WHERE "user".name = %(name_1)s {'name_1': 'Wendy'} Above, we see that ``Wendy`` is passed as a parameter to the database, while the placeholder ``:name_1`` is rendered in the appropriate form for the target database, in this case the PostgreSQL database. Similarly, :func:`.bindparam` is invoked automatically when working with :term:`CRUD` statements as far as the "VALUES" portion is concerned. The :func:`_expression.insert` construct produces an ``INSERT`` expression which will, at statement execution time, generate bound placeholders based on the arguments passed, as in:: stmt = users_table.insert() result = connection.execute(stmt, name='Wendy') The above will produce SQL output as:: INSERT INTO "user" (name) VALUES (%(name)s) {'name': 'Wendy'} The :class:`_expression.Insert` construct, at compilation/execution time, rendered a single :func:`.bindparam` mirroring the column name ``name`` as a result of the single ``name`` parameter we passed to the :meth:`_engine.Connection.execute` method. :param key: the key (e.g. the name) for this bind param. Will be used in the generated SQL statement for dialects that use named parameters. This value may be modified when part of a compilation operation, if other :class:`BindParameter` objects exist with the same key, or if its length is too long and truncation is required. :param value: Initial value for this bind param. Will be used at statement execution time as the value for this parameter passed to the DBAPI, if no other value is indicated to the statement execution method for this particular parameter name. Defaults to ``None``. :param callable\_: A callable function that takes the place of "value". The function will be called at statement execution time to determine the ultimate value. Used for scenarios where the actual bind value cannot be determined at the point at which the clause construct is created, but embedded bind values are still desirable. :param type\_: A :class:`.TypeEngine` class or instance representing an optional datatype for this :func:`.bindparam`. If not passed, a type may be determined automatically for the bind, based on the given value; for example, trivial Python types such as ``str``, ``int``, ``bool`` may result in the :class:`.String`, :class:`.Integer` or :class:`.Boolean` types being automatically selected. The type of a :func:`.bindparam` is significant especially in that the type will apply pre-processing to the value before it is passed to the database. For example, a :func:`.bindparam` which refers to a datetime value, and is specified as holding the :class:`.DateTime` type, may apply conversion needed to the value (such as stringification on SQLite) before passing the value to the database. :param unique: if True, the key name of this :class:`.BindParameter` will be modified if another :class:`.BindParameter` of the same name already has been located within the containing expression. This flag is used generally by the internals when producing so-called "anonymous" bound expressions, it isn't generally applicable to explicitly-named :func:`.bindparam` constructs. :param required: If ``True``, a value is required at execution time. If not passed, it defaults to ``True`` if neither :paramref:`.bindparam.value` or :paramref:`.bindparam.callable` were passed. If either of these parameters are present, then :paramref:`.bindparam.required` defaults to ``False``. :param quote: True if this parameter name requires quoting and is not currently known as a SQLAlchemy reserved word; this currently only applies to the Oracle backend, where bound names must sometimes be quoted. :param isoutparam: if True, the parameter should be treated like a stored procedure "OUT" parameter. This applies to backends such as Oracle which support OUT parameters. :param expanding: if True, this parameter will be treated as an "expanding" parameter at execution time; the parameter value is expected to be a sequence, rather than a scalar value, and the string SQL statement will be transformed on a per-execution basis to accommodate the sequence with a variable number of parameter slots passed to the DBAPI. This is to allow statement caching to be used in conjunction with an IN clause. .. seealso:: :meth:`.ColumnOperators.in_` :ref:`baked_in` - with baked queries .. note:: The "expanding" feature does not support "executemany"- style parameter sets. .. versionadded:: 1.2 .. versionchanged:: 1.3 the "expanding" bound parameter feature now supports empty lists. .. seealso:: :ref:`coretutorial_bind_param` :ref:`coretutorial_insert_expressions` :func:`.outparam` Nr0z [%\(\) \$]+_paramz %%(%d param)s) isinstancerr*r<r quoted_namer2rresubstrip_identifying_key _orig_keyr5r8callabler;r| expandingcoerce_compared_valuer_resolve_value_to_type) rPr<r8r%r5r|quote callable_rIr;rrs r__init__zBindParameter.__init__sD c< ( ( HE'C v  <9+344::3??? DHHJ.D/IJJDH !%  ! $  " = ,-CC)5 %;EBB t $ $ DIIIDIIIrc<|}||_|S)zrReturn a copy of this :class:`.BindParameter` in the context of an expanding IN against a tuple. )r_expanding_in_types)rPtypescloneds r_with_expanding_in_typesz&BindParameter._with_expanding_in_typess %*" rc|}||_d|_d|_|jt jurt j||_|S)zYReturn a copy of this :class:`.BindParameter` with the given value set. NF)rr8rHr|r*rrrK)rPr8rRs r _with_valuezBindParameter._with_valuesM   ;(+ + +"9%@@FK rcF|jr|S|jS)zReturn the value of this bound parameter, taking into account if the ``callable`` parameter was set. The ``callable`` value will be evaluated and returned if present, else ``value``. )rHr8rTs reffective_valuezBindParameter.effective_values$ = ==?? ": rct|}|jr-tdt ||jpdfz|_|S)Nr0r@)rDrr5r2rrGr<rOs rrzBindParameter._clonesQ   & & ; $1q{'=g>>AErc|js6d|_tdt||jpdfz|_dSdS)NTr0r@)r5r2rrGr<rTs rr}z BindParameter._convert_to_uniquesL{ DK'4$.*CGDDDHHH  rc t|to>|j|jo|j|jko|j|jkS)zJCompare this :class:`BindParameter` to the given clause. )rAr7r*_compare_type_affinityr8rHrs rrzBindParameter.comparesT um , , 0 00<< 0 ek) 0 /  rc|j}|j}|jr|}d|d<||d<|S)z4Execute a deferred value for serialization purposes.NrHr8)rHrIr8rH)rPr]vs rr^zBindParameter.__getstate__sL M    J = ! A AjM' rc|ddr8tdt||ddfz|d<|j|dS)Nr5Fr0rGr@r<)rr2rrHrrPstates r __setstate__zBindParameter.__setstate__'sj 99Xu % % +4%))K*I*IJJE%L U#####rc8d|jd|jd|jdS)NzBindParameter(z, z, type_=))r<r8r*rTs rrzBindParameter.__repr__.s) HHH JJJ III  r)rrrrr_is_crudrPr rNrSrUrrWrr}rr^rarrrrr7r7s&!NH "TTTTl     X        $$$     rr7ceZdZdZdZdZdS) TypeClausezTHandle a type keyword in a SQL statement. Used by the ``Case`` statement. typeclausec||_dSrr*r*s rrNzTypeClause.__init__?s  rN)rrrrrrNrrrrfrf6s4 "NrrfceZdZdZdZejdejZe j de iZ dZ dZedZedZgZd xZxZZdZdd Zeejd d d eddd ddZedZejddZ edZ!edZ"ddZ#e$fdZ%dZ&dZ'd S) TextClauseaRepresent a literal SQL text fragment. E.g.:: from sqlalchemy import text t = text("SELECT * FROM users") result = connection.execute(t) The :class:`_expression.TextClause` construct is produced using the :func:`_expression.text` function; see that function for full documentation. .. seealso:: :func:`_expression.text` textclausez(?.replzsA+8+D+DD QWWQZZ (1771::% %r)_bindrt_bind_params_regexrDtext)rPryr~rvs` rrNzTextClause.__init__vsK  & & & & & +//d;; r)z0.6aThe :paramref:`_expression.text.autocommit` parameter is deprecated and will be removed in a future release. Please use the :paramref:`.Connection.execution_options.autocommit` parameter in conjunction with the :meth:`.Executable.execution_options` method.)rzThe :paramref:`_expression.text.bindparams` parameter is deprecated and will be removed in a future release. Please refer to the :meth:`_expression.TextClause.bindparams` method.)rzThe :paramref:`_expression.text.typemap` parameter is deprecated and will be removed in a future release. Please refer to the :meth:`_expression.TextClause.columns` method.)rm bindparamstypemapryz :func:`.text`z:paramref:`.text.text`ct||}|r |j|}|r |jdi|}|||}|S)aConstruct a new :class:`_expression.TextClause` clause, representing a textual SQL string directly. E.g.:: from sqlalchemy import text t = text("SELECT * FROM users") result = connection.execute(t) The advantages :func:`_expression.text` provides over a plain string are backend-neutral support for bind parameters, per-statement execution options, as well as bind parameter and result-column typing behavior, allowing SQLAlchemy type constructs to play a role when executing a statement that is specified literally. The construct can also be provided with a ``.c`` collection of column elements, allowing it to be embedded in other SQL expression constructs as a subquery. Bind parameters are specified by name, using the format ``:name``. E.g.:: t = text("SELECT * FROM users WHERE id=:user_id") result = connection.execute(t, user_id=12) For SQL statements where a colon is required verbatim, as within an inline string, use a backslash to escape:: t = text("SELECT * FROM users WHERE name='\:username'") The :class:`_expression.TextClause` construct includes methods which can provide information about the bound parameters as well as the column values which would be returned from the textual statement, assuming it's an executable SELECT type of statement. The :meth:`_expression.TextClause.bindparams` method is used to provide bound parameter detail, and :meth:`_expression.TextClause.columns` method allows specification of return columns including names and types:: t = text("SELECT * FROM users WHERE id=:user_id").\ bindparams(user_id=7).\ columns(id=Integer, name=String) for id, name in connection.execute(t): print(id, name) The :func:`_expression.text` construct is used in cases when a literal string SQL fragment is specified as part of a larger query, such as for the WHERE clause of a SELECT statement:: s = select([users.c.id, users.c.name]).where(text("id=:user_id")) result = connection.execute(s, user_id=12) :func:`_expression.text` is also used for the construction of a full, standalone statement using plain text. As such, SQLAlchemy refers to it as an :class:`.Executable` object, and it supports the :meth:`Executable.execution_options` method. For example, a :func:`_expression.text` construct that should be subject to "autocommit" can be set explicitly so using the :paramref:`.Connection.execution_options.autocommit` option:: t = text("EXEC my_procedural_thing()").\ execution_options(autocommit=True) Note that SQLAlchemy's usual "autocommit" behavior applies to :func:`_expression.text` constructs implicitly - that is, statements which begin with a phrase such as ``INSERT``, ``UPDATE``, ``DELETE``, or a variety of other phrases specific to certain backends, will be eligible for autocommit if no transaction is in progress. :param text: the text of the SQL statement to be created. Use ``:`` to specify bind parameters; they will be compiled to their engine-specific format. :param autocommit: whether or not to set the "autocommit" execution option for this :class:`_expression.TextClause` object. :param bind: an optional connection or engine to be used for this text query. :param bindparams: A list of :func:`.bindparam` instances used to provide information about parameters embedded in the statement. E.g.:: stmt = text("SELECT * FROM table WHERE id=:id", bindparams=[bindparam('id', value=5, type_=Integer)]) :param typemap: A dictionary mapping the names of columns represented in the columns clause of a ``SELECT`` statement to type objects. E.g.:: stmt = text("SELECT * FROM table", typemap={'id': Integer, 'name': String}, ) .. seealso:: :ref:`sqlexpression_text` - in the Core tutorial :ref:`orm_tutorial_literal_sql` - in the ORM tutorial )r~N)rmr)rkrzrexecution_options)rPryr~rzr{rmstmts r _create_textzTextClause._create_textsm\$T***  0"4?J/D  +4<**'**D  !))Z)@@D rc|jx|_}|D]a} ||j}|||j<#t$r:}t jt jd|jz|Yd}~Zd}~wwxYw|D]h\}} ||}| |||<'#t$r5}t jt jd|z|Yd}~ad}~wwxYwdS)aEstablish the values and/or types of bound parameters within this :class:`_expression.TextClause` construct. Given a text construct such as:: from sqlalchemy import text stmt = text("SELECT id, name FROM user WHERE name=:name " "AND timestamp=:timestamp") the :meth:`_expression.TextClause.bindparams` method can be used to establish the initial value of ``:name`` and ``:timestamp``, using simple keyword arguments:: stmt = stmt.bindparams(name='jack', timestamp=datetime.datetime(2012, 10, 8, 15, 12, 5)) Where above, new :class:`.BindParameter` objects will be generated with the names ``name`` and ``timestamp``, and values of ``jack`` and ``datetime.datetime(2012, 10, 8, 15, 12, 5)``, respectively. The types will be inferred from the values given, in this case :class:`.String` and :class:`.DateTime`. When specific typing behavior is needed, the positional ``*binds`` argument can be used in which to specify :func:`.bindparam` constructs directly. These constructs must include at least the ``key`` argument, then an optional value and type:: from sqlalchemy import bindparam stmt = stmt.bindparams( bindparam('name', value='jack', type_=String), bindparam('timestamp', type_=DateTime) ) Above, we specified the type of :class:`.DateTime` for the ``timestamp`` bind, and the type of :class:`.String` for the ``name`` bind. In the case of ``name`` we also set the default value of ``"jack"``. Additional bound parameters can be supplied at statement execution time, e.g.:: result = connection.execute(stmt, timestamp=datetime.datetime(2012, 10, 8, 15, 12, 5)) The :meth:`_expression.TextClause.bindparams` method can be called repeatedly, where it will re-use existing :class:`.BindParameter` objects to add new information. For example, we can call :meth:`_expression.TextClause.bindparams` first with typing information, and a second time with value information, and it will be combined:: stmt = text("SELECT id, name FROM user WHERE name=:name " "AND timestamp=:timestamp") stmt = stmt.bindparams( bindparam('name', type_=String), bindparam('timestamp', type_=DateTime) ) stmt = stmt.bindparams( name='jack', timestamp=datetime.datetime(2012, 10, 8, 15, 12, 5) ) The :meth:`_expression.TextClause.bindparams` method also supports the concept of **unique** bound parameters. These are parameters that are "uniquified" on name at statement compilation time, so that multiple :func:`_expression.text` constructs may be combined together without the names conflicting. To use this feature, specify the :paramref:`.BindParameter.unique` flag on each :func:`.bindparam` object:: stmt1 = text("select id from table where name=:name").bindparams( bindparam("name", value='name1', unique=True) ) stmt2 = text("select id from table where name=:name").bindparams( bindparam("name", value='name2', unique=True) ) union = union_all( stmt1.columns(column("id")), stmt2.columns(column("id")) ) The above statement will render as:: select id from table where name=:name_1 UNION ALL select id from table where name=:name_2 .. versionadded:: 1.3.11 Added support for the :paramref:`.BindParameter.unique` flag to work with :func:`_expression.text` constructs. z?This text() construct doesn't define a bound parameter named %rrN) rtrIrGKeyErrorrrrritemsrU) rPbindsnames_to_values new_paramsr~existingrr<r8s rrzzTextClause.bindparamssH)-(8(=(=(?(??: 6 6D 6&dn526 8-..    %359^D%(  *//11 > >JC >%c?#+"6"6u"="= 3    %3589%(   > >s- > B0A==BC C? +C::C?zsqlalchemy.sql.selectablecfd|D}dD}||||zt|o| S)aTurn this :class:`_expression.TextClause` object into a :class:`.TextAsFrom` object that can be embedded into another statement. This function essentially bridges the gap between an entirely textual SELECT statement and the SQL expression language concept of a "selectable":: from sqlalchemy.sql import column, text stmt = text("SELECT id, name FROM some_table") stmt = stmt.columns(column('id'), column('name')).alias('st') stmt = select([mytable]).\ select_from( mytable.join(stmt, mytable.c.name == stmt.c.name) ).where(stmt.c.id > 5) Above, we pass a series of :func:`_expression.column` elements to the :meth:`_expression.TextClause.columns` method positionally. These :func:`_expression.column` elements now become first class elements upon the :attr:`.TextAsFrom.c` column collection, just like any other selectable. The column expressions we pass to :meth:`_expression.TextClause.columns` may also be typed; when we do so, these :class:`.TypeEngine` objects become the effective return type of the column, so that SQLAlchemy's result-set-processing systems may be used on the return values. This is often needed for types such as date or boolean types, as well as for unicode processing on some dialect configurations:: stmt = text("SELECT id, name, timestamp FROM some_table") stmt = stmt.columns( column('id', Integer), column('name', Unicode), column('timestamp', DateTime) ) for id, name, timestamp in connection.execute(stmt): print(id, name, timestamp) As a shortcut to the above syntax, keyword arguments referring to types alone may be used, if only type conversion is needed:: stmt = text("SELECT id, name, timestamp FROM some_table") stmt = stmt.columns( id=Integer, name=Unicode, timestamp=DateTime ) for id, name, timestamp in connection.execute(stmt): print(id, name, timestamp) The positional form of :meth:`_expression.TextClause.columns` also provides the unique feature of **positional column targeting**, which is particularly useful when using the ORM with complex textual queries. If we specify the columns from our model to :meth:`_expression.TextClause.columns`, the result set will match to those columns positionally, meaning the name or origin of the column in the textual SQL doesn't matter:: stmt = text("SELECT users.id, addresses.id, users.id, " "users.name, addresses.email_address AS email " "FROM users JOIN addresses ON users.id=addresses.user_id " "WHERE users.id = 1").columns( User.id, Address.id, Address.user_id, User.name, Address.email_address ) query = session.query(User).from_statement(stmt).options( contains_eager(User.addresses)) .. versionadded:: 1.1 the :meth:`_expression.TextClause.columns` method now offers positional column targeting in the result set when the column expressions are passed purely positionally. The :meth:`_expression.TextClause.columns` method provides a direct route to calling :meth:`_expression.FromClause.alias` as well as :meth:`_expression.SelectBase.cte` against a textual SELECT statement:: stmt = stmt.columns(id=Integer, name=String).cte('st') stmt = select([sometable]).where(sometable.c.id == stmt.c.id) .. versionadded:: 0.9.0 :func:`_expression.text` can now be converted into a fully featured "selectable" construct using the :meth:`_expression.TextClause.columns` method. cg|]:}|jvr-t|j|jn|;Sr)r<rr\)rcolrQs r z&TextClause.columns..sZ! ! ! w% %))CG"4"4 5 5 5! ! ! rc4g|]\}}t||Srr)rr<r%s rrz&TextClause.columns.. s3   )3eLe $ $   r) positional)r TextAsFromr )rPrcolsrQpositional_input_colskeyed_input_colss ` rrzTextClause.columnssL! ! ! !  ! ! !    7<{{}}   $$  !$4 4122K;K7K%   rctjSrrrTs rr*zTextClause.typerrc6|j|Sr)r*rrTs rrMzTextClause.comparatorsy++D111rc@|tjurt|S|Sr)rin_oprrs rrzTextClause.self_groups io % %D>> !Krc ztfd|jD|_dS)Nc38K|]}|j|fifVdSr)r<)rbrgrs rrz-TextClause._copy_internals..$sI  ()QUEE!NNrNN #      r)dictrtrars ``rrzTextClause._copy_internals#sV     -1-=-D-D-F-F     rc Nt|jSr)listrtrars rrzTextClause.get_children(sD$++--...rcLt|to|j|jkSr)rArkryrs rrzTextClause.compare+s %,,Hty1HHrrNNNN)(rrrrrrCrUNICODErxr _execution_optionsr"r r:rrrr _hide_fromsr<r5r8r9rN classmethodrdeprecated_paramsr"rr rzrrr*rMrrrrrrrrrkrkCs&("N#$@"*MM#6<< '(#!!!XX K%)(C(&>  < < < <T   !.V_6NOOIM}}}PO/[2}~B>B>[B>HT233s s 43s j!!X!22X2 %+    ///IIIIIrrkcReZdZdZdZejdZedZ dZ dS)NullzRepresent the NULL keyword in a SQL statement. :class:`.Null` is accessed as a constant via the :func:`.null` function. nullctjSrrrTs rr*z Null.type9rrctS)z+Return a constant :class:`.Null` construct.)rclss r _instancezNull._instance=s vv rc,t|tSr)rArrs rrz Null.compareCs%&&&rN) rrrrrrrr*rrrrrrrr/slN !!![ '''''rrcXeZdZdZdZejdZdZe dZ dZ dS)False_zRepresent the ``false`` keyword, or equivalent, in a SQL statement. :class:`.False_` is accessed as a constant via the :func:`.false` function. falsectjSrrrrTs rr*z False_.typeQ ##rctSrTrue_rTs rrzFalse_._negateUs wwrctS)aReturn a :class:`.False_` construct. E.g.:: >>> from sqlalchemy import false >>> print(select([t.c.x]).where(false())) SELECT x FROM t WHERE false A backend which does not support true/false constants will render as an expression against 1 or 0:: >>> print(select([t.c.x]).where(false())) SELECT x FROM t WHERE 0 = 1 The :func:`.true` and :func:`.false` constants also feature "short circuit" operation within an :func:`.and_` or :func:`.or_` conjunction:: >>> print(select([t.c.x]).where(or_(t.c.x > 5, true()))) SELECT x FROM t WHERE true >>> print(select([t.c.x]).where(and_(t.c.x > 5, false()))) SELECT x FROM t WHERE false .. versionchanged:: 0.9 :func:`.true` and :func:`.false` feature better integrated behavior within conjunctions and on dialects that don't support true/false constants. .. seealso:: :func:`.true` rrs rrzFalse_._instanceXsHxxrc,t|tSr)rArrs rrzFalse_.compare~s%(((rN) rrrrrrrr*rrrrrrrrrGs|N $$$##[#J)))))rrcneZdZdZdZejdZdZe dZ e dZ dZ dS) rzRepresent the ``true`` keyword, or equivalent, in a SQL statement. :class:`.True_` is accessed as a constant via the :func:`.true` function. truectjSrrrTs rr*z True_.typerrctSrrrTs rrz True_._negates xxrc2||S|Sr)r)rrs r_ifnonez True_._ifnones ===?? "LrctS)aReturn a constant :class:`.True_` construct. E.g.:: >>> from sqlalchemy import true >>> print(select([t.c.x]).where(true())) SELECT x FROM t WHERE true A backend which does not support true/false constants will render as an expression against 1 or 0:: >>> print(select([t.c.x]).where(true())) SELECT x FROM t WHERE 1 = 1 The :func:`.true` and :func:`.false` constants also feature "short circuit" operation within an :func:`.and_` or :func:`.or_` conjunction:: >>> print(select([t.c.x]).where(or_(t.c.x > 5, true()))) SELECT x FROM t WHERE true >>> print(select([t.c.x]).where(and_(t.c.x > 5, false()))) SELECT x FROM t WHERE false .. versionchanged:: 0.9 :func:`.true` and :func:`.false` feature better integrated behavior within conjunctions and on dialects that don't support true/false constants. .. seealso:: :func:`.false` rrs rrzTrue_._instancesHwwrc,t|tSr)rArrs rrz True_.compares%'''rN) rrrrrrrr*rrrrrrrrrrsN $$$[ ##[#J(((((rrcxeZdZdZdZdZdZdZedZ dZ e fdZ d Z ed Zdd Zd Zd S) ClauseListzzDescribe a list of clauses, separated by an operator. By default, is comma-separated, such as a column listing. clauselistc|dtj_|dd_|dd_|dd_|dtjrfd|D_nfd |D_tj j_ dS) NrrsTgroup_contents _tuple_valuesF_literal_as_textcXg|]&}|j'Sr)rr)rrArPtext_converters rrz'ClauseList.__init__..sFv&&11$-1HHrc&g|] }|Srr)rrArs rrz'ClauseList.__init__..s#IIIvNN622IIIr) r\rcomma_oprrsrr_expression_literal_as_textclauses is_booleanr:)rPrrvrs` @rrNzClauseList.__init__s :y/ABB ZZ.. $jj)94@@#ZZ??  ;     J%DLL JIIIIIIDL&/&:4=&I&I###rc*t|jSr)iterrrTs r__iter__zClauseList.__iter__sDL!!!rc*t|jSr)rrrTs r__len__zClauseList.__len__s4<   rc t|Sr)rrTs rrzClauseList._select_iterablesDzzrc|jrB|jt||jdS|jt|dSNr)rrappendrrr)rPrAs rrzClauseList.appendsv   : L   ((33DM3JJ      L   0 8 8 9 9 9 9 9rc <fd|jD|_dS)Nc"g|] }|fi Srr)rrArgrs rrz.ClauseList._copy_internals..s+GGGf++++GGGrrrs ``rrzClauseList._copy_internalss(GGGGG$,GGG rc |jSrrrs rrzClauseList.get_childrens |rcVttjd|jDS)Ncg|] }|j Srrrs rrz,ClauseList._from_objects..s%L%L%L!ao%L%L%Lr)r itertoolschainrrTs rrzClauseList._from_objectss(IO%L%Lt|%L%L%LMNNNrNcf|jr)tj|j|rt |S|Sr)rsr is_precedentrrrs rrzClauseList.self_groups3 : )0HH D>> !Krc "t|ts1t|jdkr|jdj|fi|St|tr2t|jt|jkr|j|jur|jt jt jfvrt}|jD]Q}t|j |D]'}|j|fi|r| |n(Rt|t|jkStdt|jD])}|j|j|j|fi|sdS*dSdS)zCompare this :class:`.ClauseList` to the given :class:`.ClauseList`, including a comparison of all the clause items. rrFT) rArrrrrrrrset differencerXrange)rPrr completedrA other_clauseis rrzClauseList.compares %,, T\1B1Ba1G1G*4<?*577B77 7 uj ) ) DL!!S%7%777 //} ???EE "l""F(+EM(:(:(E(E!))"" *6>,=="=="%MM,777!E"9~~U]););;;q#dl"3"344  A24<?25=3CJJrJJ%$uu% 45rr)rrrrrrNrrrrrrrrrrrrrrrrs "NJJJ""""!!!X:::%+HHHHOOXO rrceZdZdZdZdZedZedZedZ e dZ d fd Z d Z xZS) BooleanClauseListrFc td)Nz+BooleanClauseList has a private constructor)NotImplementedError)rPargrs rrNzBooleanClauseList.__init__&s! 9   rcvg}dtj|D}|D]Z}t||rt||r"|tjcS||[t|dkr&|dtjS|s(|r&|dtjSfd|D}||}||_ d|_ |_ d|_ tj|_d|_|S)Nc,g|]}t|Sr)r)rrAs rrz0BooleanClauseList._construct../s0    ( / /   rrrrc<g|]}|Sr)r)rrQrs rrz0BooleanClauseList._construct..As4   /0ALLL * *   rT)rcoerce_generator_argrArrrrrrGrrsrrrrr*r:) rr continue_onskip_onrrconvert_clausesrArPs ` r _constructzBooleanClauseList._construct+sr  3G<<    + +F&+.. DFG,, D((1B(CCCCC  " "6 * * * *   1 $ $"1%009J0KK K  DW D1:((1B(CC C    4C   {{3&    "( &*# rcJ|jtjttg|RS)a+Produce a conjunction of expressions joined by ``AND``. E.g.:: from sqlalchemy import and_ stmt = select([users_table]).where( and_( users_table.c.name == 'wendy', users_table.c.enrolled == True ) ) The :func:`.and_` conjunction is also available using the Python ``&`` operator (though note that compound expressions need to be parenthesized in order to function with Python operator precedence behavior):: stmt = select([users_table]).where( (users_table.c.name == 'wendy') & (users_table.c.enrolled == True) ) The :func:`.and_` operation is also implicit in some cases; the :meth:`_expression.Select.where` method for example can be invoked multiple times against a statement, which will have the effect of each clause being combined using :func:`.and_`:: stmt = select([users_table]).\ where(users_table.c.name == 'wendy').\ where(users_table.c.enrolled == True) .. seealso:: :func:`.or_` )rrrrrrrs rrzBooleanClauseList.and_Ns%Ps~ineVFgFFFFrcJ|jtjttg|RS)adProduce a conjunction of expressions joined by ``OR``. E.g.:: from sqlalchemy import or_ stmt = select([users_table]).where( or_( users_table.c.name == 'wendy', users_table.c.name == 'jack' ) ) The :func:`.or_` conjunction is also available using the Python ``|`` operator (though note that compound expressions need to be parenthesized in order to function with Python operator precedence behavior):: stmt = select([users_table]).where( (users_table.c.name == 'wendy') | (users_table.c.name == 'jack') ) .. seealso:: :func:`.and_` )rrrrrrs rrzBooleanClauseList.or_xs$<s~imVUEWEEEErc|fSrrrTs rrz"BooleanClauseList._select_iterablerrNch|js|Stt||Sr)rrrr)rPrrFs rrzBooleanClauseList.self_groups5| NK*D11<XNNNNNN (((((((rrc@eZdZdZfdZedZddZxZS)TuplezRepresent a SQL tuple.cd|D}d|D|_|d|jr |jdn tj|_t t |j|i|dS)aReturn a :class:`.Tuple`. Main usage is to produce a composite IN construct using :meth:`.ColumnOperators.in_` :: from sqlalchemy import tuple_ tuple_(table.c.col1, table.c.col2).in_( [(1, 2), (5, 12), (10, 19)] ) .. versionchanged:: 1.3.6 Added support for SQLite IN tuples. .. warning:: The composite IN construct is not supported by all backends, and is currently known to work on PostgreSQL, MySQL, and SQLite. Unsupported backends will raise a subclass of :class:`~sqlalchemy.exc.DBAPIError` when such an expression is invoked. c,g|]}t|Sr)r&rs rrz"Tuple.__init__..s!999A$Q''999rcg|] }|j Srri)rrs rrz"Tuple.__init__..s888CH888rr%rN) _type_tupler\rrr*rrrN)rPrrrFs rrNzTuple.__init__s0:999988888FF #'#3 JD Q  9J   $eT#W333333rc|fSrrrTs rrzTuple._select_iterablerrNc|tfdt||jDS)Nc @g|]\}}td||dS)NT)rrr5r%r6)rocompared_to_typerr%s rrz%Tuple._bind_param..sQ   (A'*2&6    r)rziprrrs ` `rrzTuple._bind_paramsV     ,/sD4D+E+E      *,, rr) rrrrrNrrrr<rSs@rrrsn  44444BX        rrcDeZdZdZdZddZefdZdZe dZ dS) CaseaRepresent a ``CASE`` expression. :class:`.Case` is produced using the :func:`.case` factory function, as in:: from sqlalchemy import case stmt = select([users_table]). where( case( [ (users_table.c.name == 'wendy', 'W'), (users_table.c.name == 'jack', 'J') ], else_='E' ) ) Details on :class:`.Case` usage is at :func:`.case`. .. seealso:: :func:`.case` caseNch tj|}n#t$rYnwxYw| d|D}n d|D}|r!t|ddj}nd}|d|_nt ||_||_||_|t ||_dSd|_dS)aProduce a ``CASE`` expression. The ``CASE`` construct in SQL is a conditional object that acts somewhat analogously to an "if/then" construct in other languages. It returns an instance of :class:`.Case`. :func:`.case` in its usual form is passed a list of "when" constructs, that is, a list of conditions and results as tuples:: from sqlalchemy import case stmt = select([users_table]).\ where( case( [ (users_table.c.name == 'wendy', 'W'), (users_table.c.name == 'jack', 'J') ], else_='E' ) ) The above statement will produce SQL resembling:: SELECT id, name FROM user WHERE CASE WHEN (name = :name_1) THEN :param_1 WHEN (name = :name_2) THEN :param_2 ELSE :param_3 END When simple equality expressions of several values against a single parent column are needed, :func:`.case` also has a "shorthand" format used via the :paramref:`.case.value` parameter, which is passed a column expression to be compared. In this form, the :paramref:`.case.whens` parameter is passed as a dictionary containing expressions to be compared against keyed to result expressions. The statement below is equivalent to the preceding statement:: stmt = select([users_table]).\ where( case( {"wendy": "W", "jack": "J"}, value=users_table.c.name, else_='E' ) ) The values which are accepted as result values in :paramref:`.case.whens` as well as with :paramref:`.case.else_` are coerced from Python literals into :func:`.bindparam` constructs. SQL expressions, e.g. :class:`_expression.ColumnElement` constructs, are accepted as well. To coerce a literal string expression into a constant expression rendered inline, use the :func:`_expression.literal_column` construct, as in:: from sqlalchemy import case, literal_column case( [ ( orderline.c.qty > 100, literal_column("'greaterthan100'") ), ( orderline.c.qty > 10, literal_column("'greaterthan10'") ) ], else_=literal_column("'lessthan10'") ) The above will render the given constants without using bound parameters for the result values (but still for the comparison values), as in:: CASE WHEN (orderline.qty > :qty_1) THEN 'greaterthan100' WHEN (orderline.qty > :qty_2) THEN 'greaterthan10' ELSE 'lessthan10' END :param whens: The criteria to be compared against, :paramref:`.case.whens` accepts two different forms, based on whether or not :paramref:`.case.value` is used. In the first form, it accepts a list of 2-tuples; each 2-tuple consists of ``(, )``, where the SQL expression is a boolean expression and "value" is a resulting value, e.g.:: case([ (users_table.c.name == 'wendy', 'W'), (users_table.c.name == 'jack', 'J') ]) In the second form, it accepts a Python dictionary of comparison values mapped to a resulting value; this form requires :paramref:`.case.value` to be present, and values will be compared using the ``==`` operator, e.g.:: case( {"wendy": "W", "jack": "J"}, value=users_table.c.name ) :param value: An optional SQL expression which will be used as a fixed "comparison point" for candidate values within a dictionary passed to :paramref:`.case.whens`. :param else\_: An optional SQL expression which will be the evaluated result of the ``CASE`` construct if all expressions within :paramref:`.case.whens` evaluate to false. When omitted, most databases will produce a result of NULL if none of the "when" expressions evaluate to true. Nctg|]5\}}t|t|f6Sr)r&rrrQrs rrz!Case.__init__.. sNQ#1%%00224Ea4H4HIrctg|]5\}}t|t|f6Sr) _no_literalsrr&rs rrz!Case.__init__.. sLQa++--/@/C/CDr) rdictlike_iteritemsrrr*r8r&whenselse_)rPrr8rwhenlistr%s rrNz Case.__init__sv +E22EE    D   #HH #H  "&&r*/EEE =DJJ*511DJ   *511DJJJDJJJs  $$c |j|jfi|_fd|jD|_|j|jfi|_dSdS)Nc:g|]\}}|fi|fifSrr)rxyrgrs rrz(Case._copy_internals.. s>NNN41auuQ~~"~~uuQ~~"~~6NNNrr8rrrs ``rrzCase._copy_internals sv : !tz00R00DJNNNNN4:NNN : !tz00R00DJJJ " !rc+xK|j |jV|jD] \}}|V|V|j |jVdSdSrr)rPrvrrs rrzCase.get_children si : !*   J  DAqGGGGGGG : !*      " !rcpttjd|DS)Ncg|] }|j Srrrrs rrz&Case._from_objects.. sKKK!aoKKKr)rrrrrTs rrzCase._from_objects s9 OKKt7H7H7J7JKKK L   rr rrrrrrNrrrrrrrrr r s4NZZZZx%+1111  X   rr c&t||dS)aProduce a :class:`.ColumnClause` object that has the :paramref:`_expression.column.is_literal` flag set to True. :func:`_expression.literal_column` is similar to :func:`_expression.column`, except that it is more often used as a "standalone" column expression that renders exactly as stated; while :func:`_expression.column` stores a string name that will be assumed to be part of a table and may be quoted as such, :func:`_expression.literal_column` can be that, or any other arbitrary column-oriented expression. :param text: the text of the expression; can be any SQL expression. Quoting rules will not be applied. To specify a column-name expression which should be subject to quoting rules, use the :func:`column` function. :param type\_: an optional :class:`~sqlalchemy.types.TypeEngine` object which will provide result-set translation and additional expression semantics for this column. If left as ``None`` the type will be :class:`.NullType`. .. seealso:: :func:`_expression.column` :func:`_expression.text` :ref:`sqlexpression_literal_column` T)r% is_literalr)ryr%s rliteral_columnr# sB Ed ; ; ;;rcBeZdZdZdZdZefdZdZe dZ dS)r)a`Represent a ``CAST`` expression. :class:`.Cast` is produced using the :func:`.cast` factory function, as in:: from sqlalchemy import cast, Numeric stmt = select([ cast(product_table.c.unit_price, Numeric(10, 4)) ]) Details on :class:`.Cast` usage is at :func:`.cast`. .. seealso:: :ref:`coretutorial_casts` :func:`.cast` :func:`.type_coerce` - an alternative to CAST that coerces the type on the Python side only, which is often sufficient to generate the correct SQL and data coercion. r+ctj||_t||j|_t |j|_dS)a(Produce a ``CAST`` expression. :func:`.cast` returns an instance of :class:`.Cast`. E.g.:: from sqlalchemy import cast, Numeric stmt = select([ cast(product_table.c.unit_price, Numeric(10, 4)) ]) The above statement will produce SQL resembling:: SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product The :func:`.cast` function performs two distinct functions when used. The first is that it renders the ``CAST`` expression within the resulting SQL string. The second is that it associates the given type (e.g. :class:`.TypeEngine` class or instance) with the column expression on the Python side, which means the expression will take on the expression operator behavior associated with that type, as well as the bound-value handling and result-row-handling behavior of the type. .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type to the expression such that it takes effect on the bound-value, e.g. the Python-to-database direction, in addition to the result handling, e.g. database-to-Python, direction. An alternative to :func:`.cast` is the :func:`.type_coerce` function. This function performs the second task of associating an expression with a specific type, but does not render the ``CAST`` expression in SQL. :param expression: A SQL expression, such as a :class:`_expression.ColumnElement` expression or a Python string which will be coerced into a bound literal value. :param type\_: A :class:`.TypeEngine` class or instance indicating the type to which the ``CAST`` should apply. .. seealso:: :ref:`coretutorial_casts` :func:`.type_coerce` - an alternative to CAST that coerces the type on the Python side only, which is often sufficient to generate the correct SQL and data coercion. r$N)r to_instancer*r&rArfrgrPr+r%s rrNz Cast.__init__ sBl(// ' $)DDD $TY//rc R||jfi||_||jfi||_dSrrArgrs rrzCast._copy_internals, s<eDK..2.. %66266rc |j|jfSrr)rs rrzCast.get_children0 s{DO++rc|jjSrrArrTs rrzCast._from_objects3 {((rNr rrrr)r) sx2N808080t%+7777,,,))X)))rr)cjeZdZdZdZdZefdZdZe dZ e j dZ d d ZdS) TypeCoerceaRepresent a Python-side type-coercion wrapper. :class:`.TypeCoerce` supplies the :func:`_expression.type_coerce` function; see that function for usage details. .. versionchanged:: 1.1 The :func:`.type_coerce` function now produces a persistent :class:`.TypeCoerce` wrapper object rather than translating the given object in place. .. seealso:: :func:`_expression.type_coerce` :func:`.cast` type_coercecntj||_t||j|_dS)a Associate a SQL expression with a particular type, without rendering ``CAST``. E.g.:: from sqlalchemy import type_coerce stmt = select([type_coerce(log_table.date_string, StringDateTime())]) The above construct will produce a :class:`.TypeCoerce` object, which does not modify the rendering in any way on the SQL side, with the possible exception of a generated label if used in a columns clause context:: SELECT date_string AS anon_1 FROM log When result rows are fetched, the ``StringDateTime`` type processor will be applied to result rows on behalf of the ``date_string`` column. .. note:: the :func:`.type_coerce` construct does not render any SQL syntax of its own, including that it does not imply parenthesization. Please use :meth:`.TypeCoerce.self_group` if explicit parenthesization is required. In order to provide a named label for the expression, use :meth:`_expression.ColumnElement.label`:: stmt = select([ type_coerce(log_table.date_string, StringDateTime()).label('date') ]) A type that features bound-value handling will also have that behavior take effect when literal values or :func:`.bindparam` constructs are passed to :func:`.type_coerce` as targets. For example, if a type implements the :meth:`.TypeEngine.bind_expression` method or :meth:`.TypeEngine.bind_processor` method or equivalent, these functions will take effect at statement compilation/execution time when a literal value is passed, as in:: # bound-value handling of MyStringType will be applied to the # literal value "some string" stmt = select([type_coerce("some string", MyStringType)]) When using :func:`.type_coerce` with composed expressions, note that **parenthesis are not applied**. If :func:`.type_coerce` is being used in an operator context where the parenthesis normally present from CAST are necessary, use the :meth:`.TypeCoerce.self_group` method:: >>> some_integer = column("someint", Integer) >>> some_string = column("somestr", String) >>> expr = type_coerce(some_integer + 5, String) + some_string >>> print(expr) someint + :someint_1 || somestr >>> expr = type_coerce(some_integer + 5, String).self_group() + some_string >>> print(expr) (someint + :someint_1) || somestr :param expression: A SQL expression, such as a :class:`_expression.ColumnElement` expression or a Python string which will be coerced into a bound literal value. :param type\_: A :class:`.TypeEngine` class or instance indicating the type to which the expression is coerced. .. seealso:: :ref:`coretutorial_casts` :func:`.cast` r$N)rr&r*r&rAr's rrNzTypeCoerce.__init__L s1V(// ' $)DDD rc b||jfi||_|jdddS)Ntyped_expression)rArHr\rs rrzTypeCoerce._copy_internals s<eDK..2..  ,d33333rc |jfSrr@rs rrzTypeCoerce.get_children s  ~rc|jjSrr,rTs rrzTypeCoerce._from_objects r-rct|jtr'|j}|j|_|S|jSr)rArAr7rr*)rPbps rr3zTypeCoerce.typed_expression s? dk= 1 1 ##%%BiBGI; rNcx|j|}||jurt||jS|Sr)rArr/r*)rPrgroupeds rrzTypeCoerce.self_group s>+(((99 $+ % %gty11 1Krr)rrrrrrNrrrrrrrr3rrrrr/r/8 s"#NLELELE\%+4444))X) rr/cBeZdZdZdZdZefdZdZe dZ dS)Extractz=Represent a SQL EXTRACT clause, ``extract(field FROM expr)``.extractc `tj|_||_t |d|_dS)zReturn a :class:`.Extract` construct. This is typically available as :func:`.extract` as well as ``func.extract`` from the :data:`.func` namespace. N)r INTEGERTYPEr*fieldr&r-)rPr?r-rvs rrNzExtract.__init__ s*(  %dD11 rc ,||jfi||_dSrr-rs rrzExtract._copy_internals s!E$)**r** rc |jfSrrArs rrzExtract.get_children s  |rc|jjSr)r-rrTs rrzExtract._from_objects s y&&rNr rrrr;r; sqGGN 2 2 2%+++++''X'''rr;c<eZdZdZdZdZefdZedZ dS)_label_referenceaWrap a column expression as it appears in a 'reference' context. This expression is any that includes an _order_by_label_element, which is a Label, or a DESC / ASC construct wrapping a Label. The production of _label_reference() should occur when an expression is added to this context; this includes the ORDER BY or GROUP BY of a SELECT statement, as well as a few other places, such as the ORDER BY within an OVER clause. label_referencec||_dSrrrPrs rrNz_label_reference.__init__  rc ,||jfi||_dSrrHrs rrz _label_reference._copy_internals !uT\00R00 rcdS)NrrrTs rrz_label_reference._from_objects srrN) rrrrrrNrrrrrrrrErE sh  'N%+1111XrrEc8eZdZdZdZejdZdS)_textual_label_referencetextual_label_referencec||_dSrrHrIs rrNz!_textual_label_reference.__init__ rJrc@t|jSr)rkrrrTs r _text_clausez%_textual_label_reference._text_clause s&&t|444rN)rrrrrNrrrSrrrrOrO sG.N 55555rrOceZdZdZdZ ddZedZedZedZ ed Z ed Z e d Z e d Zefd ZdZdZdZddZdS)raDefine a 'unary' expression. A unary expression has a single column expression and an operator. The operator can be placed on the left (where it is called the 'operator') or right (where it is called the 'modifier') of the column expression. :class:`.UnaryExpression` is the basis for several unary operators including those used by :func:`.desc`, :func:`.asc`, :func:`.distinct`, :func:`.nullsfirst` and :func:`.nullslast`. unaryNFc||_||_||jp|j|_t j||_||_||_dSr) rmodifierrrrr&r*rwraps_column_expression)rPrrrWr%rrXs rrNzUnaryExpression.__init__ sc!   ))M2T]*   (//  '>$$$rcTtt|tjdS)aVProduce the ``NULLS FIRST`` modifier for an ``ORDER BY`` expression. :func:`.nullsfirst` is intended to modify the expression produced by :func:`.asc` or :func:`.desc`, and indicates how NULL values should be handled when they are encountered during ordering:: from sqlalchemy import desc, nullsfirst stmt = select([users_table]).order_by( nullsfirst(desc(users_table.c.name))) The SQL expression from the above would resemble:: SELECT id, name FROM user ORDER BY name DESC NULLS FIRST Like :func:`.asc` and :func:`.desc`, :func:`.nullsfirst` is typically invoked from the column expression itself using :meth:`_expression.ColumnElement.nullsfirst`, rather than as its standalone function version, as in:: stmt = select([users_table]).order_by( users_table.c.name.desc().nullsfirst()) .. seealso:: :func:`.asc` :func:`.desc` :func:`.nullslast` :meth:`_expression.Select.order_by` FrWrX)r_literal_as_label_referencer nullsfirst_oprcolumns r_create_nullsfirstz"UnaryExpression._create_nullsfirst s0L ' / /,$)    rcTtt|tjdS)aOProduce the ``NULLS LAST`` modifier for an ``ORDER BY`` expression. :func:`.nullslast` is intended to modify the expression produced by :func:`.asc` or :func:`.desc`, and indicates how NULL values should be handled when they are encountered during ordering:: from sqlalchemy import desc, nullslast stmt = select([users_table]).order_by( nullslast(desc(users_table.c.name))) The SQL expression from the above would resemble:: SELECT id, name FROM user ORDER BY name DESC NULLS LAST Like :func:`.asc` and :func:`.desc`, :func:`.nullslast` is typically invoked from the column expression itself using :meth:`_expression.ColumnElement.nullslast`, rather than as its standalone function version, as in:: stmt = select([users_table]).order_by( users_table.c.name.desc().nullslast()) .. seealso:: :func:`.asc` :func:`.desc` :func:`.nullsfirst` :meth:`_expression.Select.order_by` FrZ)rr[r nullslast_opr]s r_create_nullslastz!UnaryExpression._create_nullslastE s0L ' / /+$)    rcTtt|tjdS)aZProduce a descending ``ORDER BY`` clause element. e.g.:: from sqlalchemy import desc stmt = select([users_table]).order_by(desc(users_table.c.name)) will produce SQL as:: SELECT id, name FROM user ORDER BY name DESC The :func:`.desc` function is a standalone version of the :meth:`_expression.ColumnElement.desc` method available on all SQL expressions, e.g.:: stmt = select([users_table]).order_by(users_table.c.name.desc()) :param column: A :class:`_expression.ColumnElement` (e.g. scalar SQL expression) with which to apply the :func:`.desc` operation. .. seealso:: :func:`.asc` :func:`.nullsfirst` :func:`.nullslast` :meth:`_expression.Select.order_by` FrZ)rr[rdesc_opr]s r _create_desczUnaryExpression._create_descq s0J ' / /&$)    rcTtt|tjdS)aSProduce an ascending ``ORDER BY`` clause element. e.g.:: from sqlalchemy import asc stmt = select([users_table]).order_by(asc(users_table.c.name)) will produce SQL as:: SELECT id, name FROM user ORDER BY name ASC The :func:`.asc` function is a standalone version of the :meth:`_expression.ColumnElement.asc` method available on all SQL expressions, e.g.:: stmt = select([users_table]).order_by(users_table.c.name.asc()) :param column: A :class:`_expression.ColumnElement` (e.g. scalar SQL expression) with which to apply the :func:`.asc` operation. .. seealso:: :func:`.desc` :func:`.nullsfirst` :func:`.nullslast` :meth:`_expression.Select.order_by` FrZ)rr[rasc_opr]s r _create_asczUnaryExpression._create_asc s0H ' / /%$)    rcdt|}t|tj|jdS)aProduce an column-expression-level unary ``DISTINCT`` clause. This applies the ``DISTINCT`` keyword to an individual column expression, and is typically contained within an aggregate function, as in:: from sqlalchemy import distinct, func stmt = select([func.count(distinct(users_table.c.name))]) The above would produce an expression resembling:: SELECT COUNT(DISTINCT name) FROM user The :func:`.distinct` function is also available as a column-level method, e.g. :meth:`_expression.ColumnElement.distinct`, as in:: stmt = select([func.count(users_table.c.name.distinct())]) The :func:`.distinct` operator is different from the :meth:`_expression.Select.distinct` method of :class:`_expression.Select`, which produces a ``SELECT`` statement with ``DISTINCT`` applied to the result set as a whole, e.g. a ``SELECT DISTINCT`` expression. See that method for further information. .. seealso:: :meth:`_expression.ColumnElement.distinct` :meth:`_expression.Select.distinct` :data:`.func` Frr%rX)r&rr distinct_opr*rr-s r_create_distinctz UnaryExpression._create_distinct s:J!&& *)$)     rc\|jtjtjfvr |jjSdSr)rWrrdrgrrrTs rrz'UnaryExpression._order_by_label_element s* =Y. 0@A A A<7 74rc|jjSrrrrTs rrzUnaryExpression._from_objects |))rc ,||jfi||_dSrrHrs rrzUnaryExpression._copy_internals rLrc |jfSrrHrs rrzUnaryExpression.get_children  rc t|to7|j|jko'|j|jko|jj|jfi|S)zcCompare this :class:`UnaryExpression` against the given :class:`_expression.ClauseElement`.)rArrrWrrrs rrzUnaryExpression.compare s[ uo . . : / : / :% $U]99b99  rcz|j3t|j|j|j|j|j|jS|jjtj jurKt| tj tj tj |jdSt|S)N)rrrWr%rXr)rr%rXr)rrrrrWr*rXrrrrrr?rDrrTs rrzUnaryExpression._negate s ; "" }i(,(D  Y %)=)L L L" 66"*(,(D  !((.. .rcf|jr)tj|j|rt|S|Sr)rrrrrs rrzUnaryExpression.self_group$ s3 = Y3DM7KK D>> !Kr)NNNNFr)rrrrrrNrr_rbrerhrmrrrrrrrrrrrrrr sf  N  %????$) ) [) V) ) [) V( ( [( T' ' [' R* * [* XX **X*%+1111    ///*rrcJeZdZdZedZedZdZdZdS)CollectionAggregatea Forms the basis for right-hand collection operator modifiers ANY and ALL. The ANY and ALL keywords are available in different ways on different backends. On PostgreSQL, they only work for an ARRAY type. On MySQL, they only work for subqueries. ct|}|jr$t|dr|}|}t |t jtj dS)aProduce an ANY expression. This may apply to an array type for some dialects (e.g. postgresql), or to a subquery for others (e.g. mysql). e.g.:: # postgresql '5 = ANY (somearray)' expr = 5 == any_(mytable.c.somearray) # mysql '5 = ANY (SELECT value FROM table)' expr = 5 == any_(select([table.c.value])) .. versionadded:: 1.1 .. seealso:: :func:`_expression.all_` as_scalarFrj) r&rrr{rryrrrrrls r _create_anyzCollectionAggregate._create_any5 st*!&&   $'$ "<"< $>>##D  " %#$)     rct|}|jr$t|dr|}|}t |t jtj dS)aProduce an ALL expression. This may apply to an array type for some dialects (e.g. postgresql), or to a subquery for others (e.g. mysql). e.g.:: # postgresql '5 = ALL (somearray)' expr = 5 == all_(mytable.c.somearray) # mysql '5 = ALL (SELECT value FROM table)' expr = 5 == all_(select([table.c.value])) .. versionadded:: 1.1 .. seealso:: :func:`_expression.any_` r{Frj) r&rrr{rryrrrrrls r _create_allzCollectionAggregate._create_allV st*!&&   $'$ "<"< $>>##D  " %#$)     rctj|stjdd|d<|jjtj|g|Ri|S)N2Only comparison operators may be used with ANY/ALLTreverse)r is_comparisonrrrMrmirrorrs rrzCollectionAggregate.operatey si&r** #D !y&t&y'7';';NeNNNvNNNrc Vtj|rJtjd)Nr)rrrrrs rrz#CollectionAggregate.reverse_operate s1*2..... @   rN) rrrrrr|r~rrrrrryry+ sw  [ @  [ DOOO     rryc"eZdZdZddZdZdS)rc||_tj|_||_||_d|_d|_|j|_dS)NT) rrrr*rrrWrXr:)rPrrrs rrNzAsBoolean.__init__ sA (     '+$&-&D###rNc|Srrrs rrzAsBoolean.self_group  rct|jttfr|jSt |j|j|jSr)rArrrrrrrrTs rrzAsBoolean._negate sG dlUFO 4 4 G<'')) )T\4; FF Frr)rrrrNrrrrrrr sNEEEGGGGGrrceZdZdZdZdZ ddZdZeZe dZ e dZ e fd Z d Zd Zdd Zfd ZxZS)r'aRepresent an expression that is ``LEFT RIGHT``. A :class:`.BinaryExpression` is generated automatically whenever two column expressions are used in a Python binary expression:: >>> from sqlalchemy.sql import column >>> column('a') + column('b') >>> print(column('a') + column('b')) a + b binaryTNct|tjrtj|}||f|_|||_|||_||_ tj ||_ ||_ tj||_| i|_dS||_dSr)rAr string_typesr custom_op_origrleftrightrrr&r*rrr: modifiers)rPrrrr%rrs rrNzBinaryExpression.__init__ s h 1 2 2 5 *844HE] OOHO55 %%h%77   (//  &/&:8&D&D#  DNNN&DNNNrc|jtjtjfvrF|t|jdt|jdSt d)Nrrr)reqner#rrrTs rrzBinaryExpression.__bool__ sW =X[(+6 6 6==djm!4!4d4:a=6I6IJJ JIJJ Jrc4tj|jSr)rrrrTs rrzBinaryExpression.is_comparison s&t}555rc4|jj|jjzSr)rrrrTs rrzBinaryExpression._from_objects sy&)AAArc R||jfi||_||jfi||_dSrrrrs rrz BinaryExpression._copy_internals s<E$)**r** U4:,,,, rc |j|jfSrrrs rrzBinaryExpression.get_children sy$*$$rc >t|to|j|jkox|jj|jfi|r|jj|jfi|pHt j|jo/|jj|jfi|o|jj|jfi|S)z[Compare this :class:`BinaryExpression` against the given :class:`BinaryExpression`.)rAr'rrrrris_commutativers rrzBinaryExpression.compare s u. / /  / " !%*3333:&DJ&u{99b99,T];;=) )%+<<<<=* *5:<<<< rcXtj|j|rt|S|Sr)rrrrrs rrzBinaryExpression.self_group s*  !$- 9 9 D>> !Krc|j3t|j|j|j|j|j|jStt|S)N)rr%r) rr'rrrr*rrrrs rrzBinaryExpression._negate s_ ; "#   }i.  )40088:: :r)NNNr)rrrrrr:rNrrrrrrrrrrrr<rSs@rr'r' s   N! IM''''(KKK K 66X6BBXB%+----%%%   $ ; ; ; ; ; ; ; ; ;rr'c$eZdZdZdZdZddZdS)SlicezRepresent SQL for a Python array-slice object. This is not a specific SQL construct at this level, but may be interpreted by specific dialects, e.g. PostgreSQL. slicecR||_||_||_tj|_dSr)startstopsteprrr*)rPrrrs rrNzSlice.__init__ s%   % rNc&|tjusJ|Sr)rgetitemrs rrzSlice.self_group s(***** rr)rrrrrrNrrrrrr sHN&&& rrceZdZdZdS)IndexExpressionzJRepresent the class of expressions that are like an "index" operation.N)rrrrrrrrr s DrrceZdZdZdZdZddZejdZ e dZ e dZ e fd Zd Ze d Ze d Zd ZdZdZdZdS)rz/Represent a grouping within a column expressiongroupingcT||_t|dtj|_dSNr*)rrrrr*rIs rrNzGrouping.__init__% s# GVX->?? rNc|Srrrs rrzGrouping.self_group) rrc|jjSrrr:rTs rr:zGrouping._is_implicitly_boolean, |22rc|jSr)r5rTs rr6zGrouping._key_label0 s {rc<t|jddp|jS)Nr5)rrrrTs rr5zGrouping._label4 st|Xt44GGrc ,||jfi||_dSrrHrs rrzGrouping._copy_internals8 rLrc |jfSrrHrs rrzGrouping.get_children; rtrcJt|jtr|jgSgSr)rArrLrTs rrzGrouping._proxies> s% dlM 2 2 L> !Irc|jjSrrprTs rrzGrouping._from_objectsE rqrc,t|j|Sr)rr)rPattrs rrzGrouping.__getattr__I st|T***rc |j|jdS)Nrr*rrTs rr^zGrouping.__getstate__L s<;;;rc:|d|_|d|_dS)Nrr*rr_s rrazGrouping.__setstate__O sY' &M rc jt|to|j|jSr)rArrrrs rrzGrouping.compareS s2%** t|/C/C M0 0  rr)rrrrrrNrrrr:rr6r5rrrrrrr^rarrrrrr s799N@@@ 333XHHXH%+1111X **X*+++<<<"""     rrRANGE_UNBOUNDED RANGE_CURRENTceZdZdZdZdZdZdZ ddZdZ dZ e e j ddd Ze jd Zd Zefd Ze d ZdS)OveraRepresent an OVER clause. This is a special operator against a so-called "window" function, as well as any aggregate function, which produces results relative to the result set itself. It's supported only by certain database backends. overNc||_|(ttj|dti|_|(ttj|dti|_|r9|||_|rtj dd|_ dS|r#|||_ d|_dSdx|_ |_dS)aI Produce an :class:`.Over` object against a function. Used against aggregate or so-called "window" functions, for database backends that support window functions. :func:`_expression.over` is usually called using the :meth:`.FunctionElement.over` method, e.g.:: func.row_number().over(order_by=mytable.c.some_column) Would produce:: ROW_NUMBER() OVER(ORDER BY some_column) Ranges are also possible using the :paramref:`.expression.over.range_` and :paramref:`.expression.over.rows` parameters. These mutually-exclusive parameters each accept a 2-tuple, which contains a combination of integers and None:: func.row_number().over( order_by=my_table.c.some_column, range_=(None, 0)) The above would produce:: ROW_NUMBER() OVER(ORDER BY some_column RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) A value of ``None`` indicates "unbounded", a value of zero indicates "current row", and negative / positive integers indicate "preceding" and "following": * RANGE BETWEEN 5 PRECEDING AND 10 FOLLOWING:: func.row_number().over(order_by='x', range_=(-5, 10)) * ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW:: func.row_number().over(order_by='x', rows=(None, 0)) * RANGE BETWEEN 2 PRECEDING AND UNBOUNDED FOLLOWING:: func.row_number().over(order_by='x', range_=(-2, None)) * RANGE BETWEEN 1 FOLLOWING AND 3 FOLLOWING:: func.row_number().over(order_by='x', range_=(1, 3)) .. versionadded:: 1.1 support for RANGE / ROWS within a window :param element: a :class:`.FunctionElement`, :class:`.WithinGroup`, or other compatible construct. :param partition_by: a column element or string, or a list of such, that will be used as the PARTITION BY clause of the OVER construct. :param order_by: a column element or string, or a list of such, that will be used as the ORDER BY clause of the OVER construct. :param range\_: optional range clause for the window. This is a tuple value which can contain integer values or ``None``, and will render a RANGE BETWEEN PRECEDING / FOLLOWING clause. .. versionadded:: 1.1 :param rows: optional rows clause for the window. This is a tuple value which can contain integer values or None, and will render a ROWS BETWEEN PRECEDING / FOLLOWING clause. .. versionadded:: 1.1 This function is also available from the :data:`~.expression.func` construct itself via the :meth:`.FunctionElement.over` method. .. seealso:: :data:`.expression.func` :func:`_expression.within_group` Nrz*'range_' and 'rows' are mutually exclusive) rrrto_listr[order_by partition_by_interpret_rangerange_rrrows)rPrrrrrs rrNz Over.__init__q sf  &h''!<DM  # *l++!!<!!D   +//77DK !'@!  +--d33DIDKKK&* *DI rcP|j|j|j|j|j|jffSr)rFrrrrrrTs r __reduce__zOver.__reduce__ s0~ L   M K I    rcNt|trt|dkrtjd|dt }nc t |d}|dkrt}n?#t$r2}tj tjd|Yd}~nd}~wwxYw|dt }nc t |d}|dkrt}n?#t$r2}tj tjd|Yd}~nd}~wwxYw||fS)Nrz2-tuple expected for range/rowsrz(Integer or None expected for range valuerr) rAtuplerrrrintr ValueErrorrr)rPrlowerruppers rrzOver._interpret_range s&%(( GCKK1,<,<#$EFF F !9 #EE *F1IA::)E    %B%(   !9 #EE *F1IA::)E    %B%(  e|s0A11 B-;(B((B-C$$ D .(DD z1.1zthe :attr:`.Over.func` member of the :class:`.Over` class is deprecated and will be removed in a future release. Please refer to the :attr:`.Over.element` attribute.c|jS)zIthe element referred to by this :class:`.Over` clause. rHrTs rfuncz Over.func s |rc|jjSrrrTs rr*z Over.types |  rc >d|j|j|jfDS)Ncg|]}||Srrrs rrz%Over.get_children..!s%   } }}rrrrrs rrzOver.get_children s1  lD$5t}E    rc ||jfi||_|j||jfi||_|j||jfi||_dSdSrrrs rrzOver._copy_internals'sruT\00R00   ( %d&7 > >2 > >D  = $!E$-66266DMMM % $rcpttjd|j|j|jfDS)Nc g|] }||j Srrrs rrz&Over._from_objects..2'}O$}}r)rrrrrrrTs rrzOver._from_objects.sH O"lD,=t}M    rr)rrrrrrrrrNrrrrrrrr*rrrrrrrrr] sNHLGLPk+k+k+k+Z   $$$LT_  ?  X !!!   %+7777   X    rrcneZdZdZdZdZdZd dZej dZ dZ e fdZ ed ZdS) WithinGroupaRepresent a WITHIN GROUP (ORDER BY) clause. This is a special operator against so-called "ordered set aggregate" and "hypothetical set aggregate" functions, including ``percentile_cont()``, ``rank()``, ``dense_rank()``, etc. It's supported only by certain database backends, such as PostgreSQL, Oracle and MS SQL Server. The :class:`.WithinGroup` construct extracts its type from the method :meth:`.FunctionElement.within_group_type`. If this returns ``None``, the function's ``.type`` is used. withingroupNcl||_|*ttj|dti|_dSdS)aProduce a :class:`.WithinGroup` object against a function. Used against so-called "ordered set aggregate" and "hypothetical set aggregate" functions, including :class:`.percentile_cont`, :class:`.rank`, :class:`.dense_rank`, etc. :func:`_expression.within_group` is usually called using the :meth:`.FunctionElement.within_group` method, e.g.:: from sqlalchemy import within_group stmt = select([ department.c.id, func.percentile_cont(0.5).within_group( department.c.salary.desc() ) ]) The above statement would produce SQL similar to ``SELECT department.id, percentile_cont(0.5) WITHIN GROUP (ORDER BY department.salary DESC)``. :param element: a :class:`.FunctionElement` construct, typically generated by :data:`~.expression.func`. :param \*order_by: one or more column elements that will be used as the ORDER BY clause of the WITHIN GROUP construct. .. versionadded:: 1.1 .. seealso:: :data:`.expression.func` :func:`_expression.over` Nr)rrrrr[r)rPrrs rrNzWithinGroup.__init__PsDH  &h''!<DMMM rc*t|||||S)zProduce an OVER clause against this :class:`.WithinGroup` construct. This function has the same signature as that of :meth:`.FunctionElement.over`. rrrrrrPrrrrs rrzWithinGroup.over{s* %     rcV|j|}||S|jjSr)rwithin_group_typer*)rPwgts rr*zWithinGroup.types,l,,T22 ?J<$ $rc 2d|j|jfDS)Ncg|]}||Srrrs rrz,WithinGroup.get_children..sJJJaAMMMMrrrrs rrzWithinGroup.get_childrensJJDL$-8JJJJrc d||jfi||_|j||jfi||_dSdSrrrs rrzWithinGroup._copy_internalssLuT\00R00 = $!E$-66266DMMM % $rcdttjd|j|jfDS)Nc g|] }||j Srrrs rrz-WithinGroup._from_objects..rr)rrrrrrTs rrzWithinGroup._from_objectssC O"lDM:    rr)rrrrrrrNrrrr*rrrrrrrrrr;s #NH)))V     %%%KKK%+7777    X    rrc|eZdZdZdZdZdZdZd dZd dZ e j dZ d Z efd Zed ZdS)FunctionFilteraRepresent a function FILTER clause. This is a special operator against aggregate and window functions, which controls which rows are passed to it. It's supported only by certain database backends. Invocation of :class:`.FunctionFilter` is via :meth:`.FunctionElement.filter`:: func.count(1).filter(True) .. versionadded:: 1.0.0 .. seealso:: :meth:`.FunctionElement.filter` funcfilterNc(||_|j|dS)aProduce a :class:`.FunctionFilter` object against a function. Used against aggregate and window functions, for database backends that support the "FILTER" clause. E.g.:: from sqlalchemy import funcfilter funcfilter(func.count(1), MyClass.name == 'some name') Would produce "COUNT(1) FILTER (WHERE myclass.name = 'some name')". This function is also available from the :data:`~.expression.func` construct itself via the :meth:`.FunctionElement.filter` method. .. versionadded:: 1.0.0 .. seealso:: :meth:`.FunctionElement.filter` N)rfilter)rPr criterions rrNzFunctionFilter.__init__s 0  Yrct|D]/}t|}|j|j|z|_(||_0|S)a Produce an additional FILTER against the function. This method adds additional criteria to the initial criteria set up by :meth:`.FunctionElement.filter`. Multiple criteria are joined together at SQL render time via ``AND``. )rrr)rPrs rrzFunctionFilter.filtersLi + +I3I>>I~)!%)!;!* rc*t|||||S)aProduce an OVER clause against this filtered function. Used against aggregate or so-called "window" functions, for database backends that support window functions. The expression:: func.rank().filter(MyClass.y > 5).over(order_by='x') is shorthand for:: from sqlalchemy import over, funcfilter over(funcfilter(func.rank(), MyClass.y > 5), order_by='x') See :func:`_expression.over` for a full description. rrrs rrzFunctionFilter.overs*$ %     rcbtjtj|rt|S|Sr)rr filter_oprrs rrzFunctionFilter.self_group s+  !)"5w ? ? D>> !Krc|jjSr)rr*rTs rr*zFunctionFilter.types y~rc 2d|j|jfDS)Ncg|]}||Srrrs rrz/FunctionFilter.get_children..sHHHa!----rrrrs rrzFunctionFilter.get_childrensHHDIt~6HHHHrc d||jfi||_|j||jfi||_dSdSrrrs rrzFunctionFilter._copy_internalssLE$)**r** > %"U4>88R88DNNN & %rcdttjd|j|jfDS)Nc g|] }||j Srrrs rrz0FunctionFilter._from_objects..!rr)rrrrrrTs rrzFunctionFilter._from_objectssC O"i8    rrr)rrrrrrrNrrrrrr*rrrrrrrrrrs&"NI   6,    4  III%+9999    X    rrc*eZdZdZdZddZdZejdZ ejdZ e dZ ejd Z ejd Zdd Zd Zd Ze dZe dZdZedfdZe dZddZdS)r-zRepresents a column label (AS). Represent a label, as typically applied to any column-level element using the ``AS`` sql keyword. r.Nc t|tr |j|_t|tr|j}t|t|r||_|j|_n5t dt|t|ddfz|_|jx|_ x|_|_ ||_ ||_ |g|_ dS)aReturn a :class:`Label` object for the given :class:`_expression.ColumnElement`. A label changes the name of an element in the columns clause of a ``SELECT`` statement, typically via the ``AS`` SQL keyword. This functionality is more conveniently available via the :meth:`_expression.ColumnElement.label` method on :class:`_expression.ColumnElement`. :param name: label name :param obj: a :class:`_expression.ColumnElement`. r0rr1N)rAr-r5r8rrr2rrr<r6_element_typer)rPrrr%s rrNzLabel.__init__4s" gu % % 1").D %(( &oG%(( &  DI"&)D  (4''66*J*JKKDI489<<4;    rc8|j|j|j|jffSr)rFrrrrTs rrzLabel.__reduce__Xs~ 4=$*EEErc|jjSrrrTs rr:zLabel._is_implicitly_boolean[rrc|jjSr)rr9rTs rr9zLabel._allow_label_resolve_s |00rc|SrrrTs rrzLabel._order_by_label_elementcs rc`tj|jpt|jddSr)rr&rrrrTs rr*z Label.typegs/# J >'$->>   rcL|jtjSr)rrras_rTs rrz Label.elementms}'' '>>>rcD||jj|Sr)_apply_to_innerrrrs rrzLabel.self_groupqs ##DM$b#nnn dm + +KtzBBB BKrc|jjSr)rr3rTs rr3zLabel.primary_key~s |''rc|jjSr)rr4rTs rr4zLabel.foreign_keyss |((rc |jfSrrHrs rrzLabel.get_childrenrtrFc V||jfi||_|jdd|jdd|r]tdt |t |jddfzx|_|_|jx|_ x|_ |_ dSdS)Nrr9r0rr1) rrHr\r2rrrrr8r<r5r6)rPrganonymize_labelsrs rrzLabel._copy_internalssdm22r22  )T*** 0$777  A.>d88WT\66BBCD// DI+8>>rTc|j}|jrdS|/|jr't|ddr-|jdddz|jzdz|z}n |jdz|z}t|dd8t|tr |j |_ n]t||j }nGt|jdd1t|trJt||jj }|r;||j vr2|}d}||j vr#|dzt|z}|dz }||j v#|}t|S|S)Nschema.r?rLr) rr"named_with_columnrr1replacerrArBrLrQrr)rPrr.r&r.r5counters rr)zColumnClause._gen_labelssj J ?) 4 ]q2]q(D)) ,((c22S816ACG$N t+tWd++7e[11;"&*EKK'tz::EE$//;&e[99999#E16<88 #AC<<"FG AC--!&s7||!;1 !AC--#E '' 'Krc@t|j|||j|dS)NT)rrr%r5)r7r<r*rs rrzColumnClause._bind_params/ H "*"i     rc `| o|jo|dup ||jk}||rt|p|jn|p|j|j||}| |j|_|g|_|j)|jj |j|_|r||j |j<|S)N)r%rr") r"rrUrr*r<rrNrrr) rPrrattachrrrr"rQs rr zColumnClause._make_proxys $ #    %49$    " %M$+$) , , ,#$))"!    <HAEV  " .'4<@@GGAN  +)*J  &r)NFN)Tr)NTFF)rrrrronupdaterserver_defaultserver_onupdate_is_multiparam_columnr!group_expirable_memoized_propertyr!rNrrr#rrrrrr6r5r7r/r)rr rrrrrs##JN<@@H@w@/!??AA_%_%_%_%B@@@*&&&''' HZ , ,E AAA  ***&&&??X?,,,,\    !! ))))))rrceZdZdZdZdS)r(r,c||_dSr)r,)rPr,s rrNzCollationClause.__init__s "rN)rrrrrNrrrr(r(s( N#####rr(cPeZdZdZejddiZdZdS)_IdentifiedClause identifiedrmFc||_dSr)ident)rPrDs rrNz_IdentifiedClause.__init__s  rN)rrrrr rr"rNrrrrArAsI!N#6<< urrAceZdZdZdS)SavepointClause savepointNrrrrrrrrFrFs NNNrrFceZdZdZdS)RollbackToSavepointClauserollback_to_savepointNrHrrrrJrJs,NNNrrJceZdZdZdS)ReleaseSavepointClauserelease_savepointNrHrrrrMrMs(NNNrrMc>eZdZdZdZfdZdZdZdZdZ xZ S)rBaRepresent a SQL identifier combined with quoting preferences. :class:`.quoted_name` is a Python unicode/str subclass which represents a particular identifier name along with a ``quote`` flag. This ``quote`` flag, when set to ``True`` or ``False``, overrides automatic quoting behavior for this identifier in order to either unconditionally quote or to not quote the name. If left at its default of ``None``, quoting behavior is applied to the identifier on a per-backend basis based on an examination of the token itself. A :class:`.quoted_name` object with ``quote=True`` is also prevented from being modified in the case of a so-called "name normalize" option. Certain database backends, such as Oracle, Firebird, and DB2 "normalize" case-insensitive names as uppercase. The SQLAlchemy dialects for these backends convert from SQLAlchemy's lower-case-means-insensitive convention to the upper-case-means-insensitive conventions of those backends. The ``quote=True`` flag here will prevent this conversion from occurring to support an identifier that's quoted as all lower case against such a backend. The :class:`.quoted_name` object is normally created automatically when specifying the name for key schema constructs such as :class:`_schema.Table`, :class:`_schema.Column`, and others. The class can also be passed explicitly as the name to any function that receives a name which can be quoted. Such as to use the :meth:`_engine.Engine.has_table` method with an unconditionally quoted name:: from sqlalchemy import create_engine from sqlalchemy.sql import quoted_name engine = create_engine("oracle+cx_oracle://some_dsn") engine.has_table(quoted_name("some_table", True)) The above logic will run the "has table" logic against the Oracle backend, passing the name exactly as ``"some_table"`` without converting to upper case. .. versionadded:: 0.9.0 .. versionchanged:: 1.2 The :class:`.quoted_name` construct is now importable from ``sqlalchemy.sql``, in addition to the previous location of ``sqlalchemy.sql.elements``. )rLrrc|dSt||r| |j|kr|Stt|||}||_|Sr)rArLrrBrG)rr8rLrPrFs rrGzquoted_name.__new__)sb =4 s # #  MU[E11L[#&&..sE::  rcFttj||jffSr)rBr text_typerLrTs rrzquoted_name.__reduce__:sT^D114:>>>rc`|jr|Stj|Sr)rLrrRrrTs r_memoized_method_lowerz"quoted_name._memoized_method_lower=- : 0K>$''--// /rc`|jr|Stj|Sr)rLrrRrrTs r_memoized_method_upperz"quoted_name._memoized_method_upperCrUrctjr<|dd}tjs|d}d|zSt|S)Nrrz'%s')rpy2krdecoderr)rP backslasheds rrzquoted_name.__repr__IsZ 9 &++g/ABBK9 :)0099 K' '<<%% %r) rrrr __slots__rGrrTrWrr<rSs@rrBrBs//b*I"???000 000 &&&&&&&rrBc4eZdZdZdZdfd ZdZdZxZS)_truncated_labelzVA unicode subclass used to identify symbolic " "names that may require truncation.rNczt|d|}tt||||S)NrL)rrr^rG)rr8rLrFs rrGz_truncated_label.__new__Ys7w..%s++33CFFFrcF|jtj||jffSr)rFrrRrLrTs rrz_truncated_label.__reduce__^s ~t 4 4djAAArc|SrrrPmap_s r apply_mapz_truncated_label.apply_maparrr) rrrrr\rGrrdr<rSs@rr^r^Ssu++IGGGGGG BBBrr^ceZdZdZdZdS)convaMark a string indicating that a name has already been converted by a naming convention. This is a string subclass that indicates a name that should not be subject to any further naming conventions. E.g. when we create a :class:`.Constraint` using a naming convention as follows:: m = MetaData(naming_convention={ "ck": "ck_%(table_name)s_%(constraint_name)s" }) t = Table('t', m, Column('x', Integer), CheckConstraint('x > 5', name='x5')) The name of the above constraint will be rendered as ``"ck_t_x5"``. That is, the existing name ``x5`` is used in the naming convention as the ``constraint_name`` token. In some situations, such as in migration scripts, we may be rendering the above :class:`.CheckConstraint` with a name that's already been converted. In order to make sure the name isn't double-modified, the new name is applied using the :func:`_schema.conv` marker. We can use this explicitly as follows:: m = MetaData(naming_convention={ "ck": "ck_%(table_name)s_%(constraint_name)s" }) t = Table('t', m, Column('x', Integer), CheckConstraint('x > 5', name=conv('ck_t_x5'))) Where above, the :func:`_schema.conv` marker indicates that the constraint name here is final, and the name will render as ``"ck_t_x5"`` and not ``"ck_t_ck_t_x5"`` .. versionadded:: 0.9.4 .. seealso:: :ref:`constraint_naming_conventions` rN)rrrrr\rrrrfrfes **XIIIrrf NONE_NAMEc(eZdZdZdZdZdZdZdS)r2zDA unicode subclass used to identify anonymously generated names.rc tttj|tj||jSrr2rBrrR__add__rLrs rrkz_anonymous_label.__add__sD &&tT^E-B-BCCTZ     rc tttjtj|||jSrrjrs r__radd__z_anonymous_label.__radd__sD &&t~e'<'.s===qQ]===rrrelementss r_expand_clonedrxs ?==H=== >>rc2tjd|DS)zXExpand tables into individual columns in the given list of column expressions. cg|] }|j Sr)rrs rrz%_select_iterables..sBBBAQ/BBBrrurvs r_select_iterablesr{s ?BBBBB CCrctt|t|tfd|DS)zReturn the intersection of sets a and b, counting any overlap between 'cloned' predecessors. The returned set is in terms of the entities present within 'a'. c3PK|] }|j|V!dSrrrJrelem all_overlaps rrz'_cloned_intersection..sMk66t7GHH rrrxrarrs @r_cloned_intersectionrshnQ''((55nQ6G6GHHK   rctt|t|tfd|DS)Nc3PK|] }|j|V!dSrr~rs rrz%_cloned_difference..sM+":":4;K"L"L rrrs @r_cloned_differencersfnQ''((55nQ6G6GHHK   rzsqlalchemy.sql.functionsczt|drt||jr|dS|S)Nr)rrAFunctionElementr.) functionsrs r_labeledrsF 7F # #z*((}}T"""rc,t|tS)zITrue if ``col`` is an instance of :class:`_expression.ColumnElement`.)rArL)rs r _is_columnrs c= ) ))rc\tj}t|id|ji|S)z2Locate Column objects within the given expression.r^)rrWrrX)rArs r _find_columnsr s/ ?  D VR(DH-... Krct|tjr|St|dr|} |jS#t $rYdSwxYwN__clause_element__)rArrrrr<rrHs r_column_as_keyrso'4,--w,--/,,..{ ttsA AAcNt|dr|S|Sr)rrrHs r_clause_element_as_exprr)s,w,--))+++rct|tjrt|St |dr|}t |Sr)rArrrOrrrrHs rr[r[0sW'4,--/'000 . / //,,.. G $ $$rct|tjrt|St |dr|}t|t r|jt|St|Sr) rArrrOrrrLrrErrHs r&_literal_and_labels_as_label_referencer:s'4,--/'000 . / //,,.. 7M**)  + 7((((((rc t|Sr)rrHs rrrJs G $ $$rcjt|tr|St|dr|St|tjr ||St|tjtfrt|Stj dt|z)Nrz=SQL expression object expected, got object of type %r instead) rArrrrrNoneTyper  _const_exprrrr*)r text_fallbacks r _literal_asrNs'9%%   . / /  ))+++ GT. / / }W%%% GdmT2 3 3 7### W  &   rcZ|rt|tSt|tSr)rrk_no_text_coercion)rallow_coercion_to_texts rrr^s+77J///7$5666rc,t|tSr)rrrHs r_literal_as_columnres w - --rct|}t| }tjdt j||rdnddz)NzTextual column expression %(column)r should be explicitly declared with text(%(column)r), or use %(literal_column)s(%(column)r) for more specificityr#r^)r^r#)r_guess_straight_columnmatchrrrellipses_string)rguess_is_literals r_no_column_coercionrisn'llG177@@@   *733..      rctj|dtj||rd|znddz|dS)NzX%(extra)sTextual SQL expression %(expr)r should be explicitly declared as text(%(expr)r)z%s )r-extrar)rrr)rexc_clsrrs rrrzso K 4,W55*/7R         rct|dr|St|tst jd|d|S)NrzAmbiguous literal: zl. Use the 'text()' function to indicate a SQL expression literal, or 'literal()' to indicate a bound value.)rrrArrrrHs rrrsfw,-- ))+++  + +&gg (   rcPt|t ot|d Sr)rArrrHs r _is_literalrs3'9-- - g%773rc*|dSt||Sr)_only_column_elementsrrs r_only_column_elements_or_nonerst$Wd333rc t|dr|}t|ts*t jd|d|dt ||S)Nrz6Column-based expression object expected for argument 'z '; got: 'z', type )rrrArLrrr*rs rrrstw,--/,,.. g} - - *.$$g H    Nrct|dr|St|ts#|t St |||dS|S)NrTr4)rrrArrr7)rrr%s rr&r&scw,--))+++  + + ?66M weDIII Irz^\w\S*$ct|tr|St|dr|St j|d}|1t|t jtfrt|Snt|dr|j S|dkrd}nGt|tj rtt|dSt|t||S)NrF)raiseerrr*T)r")rArrrrinspectrrr rrnumbersNumberrrr)rinsprs r_interpret_as_column_or_fromrs'9%%, . / /,))+++  g 6 6 6D | g t4 5 5 (w'' ' ( | $ $#~~ Ggn . .%CLLT::::G$$$ ,< = = ==rct|tttfr|S|tS|durtS|durtSt jd)NFTzExpected None, False, or True)rArrrrrrHs rrrsg'D&%011 A vv E  xx Dww ?@@@rcN|D]}|jjs |jcStjSr)r*_isnullrr)argsrs r_type_from_argsrs8 !!v~ 6MMM   rc |||}|2tjd|dt|ddd|jd|S)N)require_embeddedzGiven column 'z', attached to table 'rz7', failed to locate a corresponding column from table '')corresponding_columnrInvalidRequestErrorrr) fromclauser^rrQs r_corresponding_column_or_errorrsv''!1 (  A y%%vvwvw5555z7M7M7M O   HrceZdZdZfdZejdZejdZejdZ ejdZ ejdZ xZ S)AnnotatedColumnElementctj|||tj|dD]7}|j|d|j|8dS)N)rr<rF)rrNrLrMrKrHrr\)rPrrars rrNzAnnotatedColumnElement.__init__sv4&111 ''---, ( (D}  u--5 !!$''' ( (rctt||}tj||Sr)rrrerLrMrK)rPrargrFs rrez(AnnotatedColumnElement._with_annotationss=,d33EEfMM ''... rc|jjS)z'Pull 'name' from parent, if not present)_Annotated__elementrrTs rrzAnnotatedColumnElement.names',,rc|jjS)z(Pull 'table' from parent, if not present)rrrTs rrzAnnotatedColumnElement.table s'--rc|jjS)z&Pull 'key' from parent, if not present)rr<rTs rr<zAnnotatedColumnElement.keys'++rc|jjSr)rinforTs rrzAnnotatedColumnElement.infos',,rc|jjSr)rrrTs rrz!AnnotatedColumnElement.anon_labels'22r) rrrrNrerrrrr<rrr<rSs@rrrs(((  --- ... ,,, --- 3333333rr)Frr)tr __future__rrrrrCrrr annotationrbaser r r r r visitorsrrrrrrrr"r)r0r9r=rB_self_inspectsrDColumnOperatorsrLr7rfrkrrrrrrrrr r#r)r/r;rErOrryrr'rrrsymbolrrrrrr-rr(rArFrJrM MemoizedSlotsrRrBr^rf _NONE_NAME_generated_labelr2rrrrxr{rrrrrrrrr[rrrrrrrrrrrrr&rIrrrrrrrrrrs  (''''' !!!!!!""""""%%%%%%   25G5G5G5Gp@@@@, P P P P444 oooooIoood A A A A A I-}A A A H G G G G G MG G G T        iIiIiIiIiI]iIiIiIX'''''='''08)8)8)8)8)]8)8)8)v?(?(?(?(?(M?(?(?(DZZZZZZZZzB(B(B(B(B( MB(B(B(J55555J 555pM M M M M =M M M `!<!<!<!>>0 A A A!!!     "3"3"3"3"3Y"3"3"3"3"3r