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ZQdre1fdsYZRdtS(us6SQL function API, factories, and built-in functions. i(t annotation(t operators(tschema(tsqltypes(tutil(tColumnCollection(t Executable(t_clone(t_literal_as_binds(t_type_from_args(tBinaryExpression(t BindParameter(tCast(t ClauseList(t ColumnElement(tExtract(tFunctionFilter(tGrouping(tliteral_column(tOver(t WithinGroup(tAlias(t FromClause(tSelect(t VisitableTypeicCs tjtS(N(Rt defaultdicttdict(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyt(ttnametcase_sensitive_functiontdocsHSymbol to mark the functions that are switched into case-sensitive mode.t_defaultcCs,t|}t|}|}|j}||kr||tk r|||krutjdj|||||jd}||j||_tt|j|dS(NRZ(tpopRzRrRRR\(R;R[RZ((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR\s(RsRtR@RxR}tsetterR~R\(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRRs  t_FunctionGeneratorcBs)eZdZdZdZdZRS(s;Generate :class:`.Function` objects based on getattr calls.cKsg|_||_dS(N(t_FunctionGenerator__namestopts(R;R((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR@s cCs|jdrAy|j|SWq`tk r=t|q`Xn|jdr`|dd!}nt|j}t|j|g|_|S(Nt__t_ii( t startswitht__dict__tKeyErrortAttributeErrortendswithRRR(R(R;Rtf((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyt __getattr__s c Os|jj}|j|t|j}|dkrI|j\}}n)|dkrld|jd}}nd}|dk rt|j|j}|t krt |}|j|jj|}n|dk r|||Snt |jdd|jdd!||S(NiiR iiRv( RtcopytupdatetlenRRGR!tgetR#R$R"tFunction( R;R>R=tottokensR-tfnametfuncR/((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyt__call__s"      ! (RsRtRuR@RR(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRs  tgroupRcBs)eZdZdZdZddZRS(sYDescribe a named SQL function. See the superclass :class:`.FunctionElement` for a description of public methods. .. seealso:: :data:`.func` - namespace which produces registered or ad-hoc :class:`.Function` instances. :class:`.GenericFunction` - allows creation of registered function types. tfunctioncOsn|jddpg|_||_|jdd|_tj|jdd|_t j |||dS(sConstruct a :class:`.Function`. The :data:`.func` construct is normally used to construct new :class:`.Function` instances. RvtbindRjN( RRGRvRRt_bindRt to_instanceRkR2R@(R;RR<R[((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR@_s  c Cs+t|j|d|d|jd|dtS(NRgRhRjRi(R RRkR8(R;R3RlRj((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRmms N(RsRtRut__visit_name__R@RGRm(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRMs t _GenericMetacBseZdZRS(cCstj|jkr|jd||_}|jd||_}|jdd}d|krr|d|_nt|dt |_ |j rt |||qt |_ nt t |j|||dS(NRR+R-R t__return_type__t _register(Rt Annotatedt__mro__RRR+RRktgetattrR8RR1RrRR@(tclstclsnametbasestclsdictRR+R-((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR@ys   (RsRtR@(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRxstGenericFunctioncBs#eZdZeZeZdZRS(sDefine a 'generic' function. A generic function is a pre-established :class:`.Function` class that is instantiated automatically when called by name from the :data:`.func` attribute. Note that calling any name from :data:`.func` has the effect that a new :class:`.Function` instance is created automatically, given that name. The primary use case for defining a :class:`.GenericFunction` class is so that a function of a particular name may be given a fixed return type. It can also include custom argument parsing schemes as well as additional methods. Subclasses of :class:`.GenericFunction` are automatically registered under the name of the class. For example, a user-defined function ``as_utc()`` would be available immediately:: from sqlalchemy.sql.functions import GenericFunction from sqlalchemy.types import DateTime class as_utc(GenericFunction): type = DateTime print select([func.as_utc()]) User-defined generic functions can be organized into packages by specifying the "package" attribute when defining :class:`.GenericFunction`. Third party libraries containing many functions may want to use this in order to avoid name conflicts with other systems. For example, if our ``as_utc()`` function were part of a package "time":: class as_utc(GenericFunction): type = DateTime package = "time" The above function would be available from :data:`.func` using the package name ``time``:: print select([func.time.as_utc()]) A final option is to allow the function to be accessed from one name in :data:`.func` but to render as a different name. The ``identifier`` attribute will override the name used to access the function as loaded from :data:`.func`, but will retain the usage of ``name`` as the rendered name:: class GeoBuffer(GenericFunction): type = Geometry package = "geo" name = "ST_Buffer" identifier = "buffer" The above function will render as follows:: >>> print func.geo.buffer() ST_Buffer() cOs|jdd}|dkrFg|D]}t||j^q%}n|jpXt||_g|_|jdd|_t dt j dt |j |_tj|jddpt|dd|_dS(Nt _parsed_argsRR3R4RjRk(RRGRRR5R6RvRRR RR7R8R9R:RRRRk(R;R?R=t parsed_argsR>((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR@s ( (RsRtRuR8tcoerce_argumentsRwRR@(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRs=tcasttextractt next_valuecBs8eZdZejZdZdZedZ RS(sRepresent the 'next value', given a :class:`.Sequence` as its single argument. Compiles into the appropriate function on each backend, or will raise NotImplementedError if used on a backend that does not provide support for sequences. RcKs@t|tjstd|jdd|_||_dS(Ns0next_value() accepts a Sequence object as input.R(RpRtSequencetAssertionErrorRRGRtsequence(R;tseqR[((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR@s  cCsgS(N((R;((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRVs( RsRtRuRtIntegerRkRR@RxRV(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRs   t AnsiFunctioncBseZdZRS(cOstj|||dS(N(RR@(R;R?R=((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR@s(RsRtR@(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRstReturnTypeFromArgscBseZdZdZRS(sADefine a function whose return type is the same as its arguments.cOsbg|D]}t||j^q}|jdt|||d((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR@s% (RsRtRuR@(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRstcoalescecBseZeZRS((RsRtR8R5(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR stmaxcBseZRS((RsRt(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRstmincBseZRS((RsRt(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRstsumcBseZRS((RsRt(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRstnowcBseZejZRS((RsRtRtDateTimeRk(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRstconcatcBseZejZRS((RsRtRtStringRk(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR st char_lengthcBseZejZdZRS(cKstj|||dS(N(RR@(R;targR=((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR@'s(RsRtRRRkR@(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR$s trandomcBseZeZRS((RsRtR8R5(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR+stcountcBs#eZdZejZddZRS(sThe ANSI COUNT aggregate function. With no arguments, emits COUNT \*. E.g.:: from sqlalchemy import func from sqlalchemy import select from sqlalchemy import table, column my_table = table('some_table', column('id')) stmt = select([func.count()]).select_from(my_table) Executing ``stmt`` would emit:: SELECT count(*) AS count_1 FROM some_table cKs8|dkrtd}ntt|j||dS(Nt*(RGRRrRR@(R;t expressionR=((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR@Fs N(RsRtRuRRRkRGR@(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR/s t current_datecBseZejZRS((RsRtRtDateRk(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRLst current_timecBseZejZRS((RsRtRtTimeRk(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRPstcurrent_timestampcBseZejZRS((RsRtRRRk(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRTst current_usercBseZejZRS((RsRtRRRk(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRXst localtimecBseZejZRS((RsRtRRRk(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR\stlocaltimestampcBseZejZRS((RsRtRRRk(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR`st session_usercBseZejZRS((RsRtRRRk(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRdstsysdatecBseZejZRS((RsRtRRRk(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRhstusercBseZejZRS((RsRtRRRk(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRlst array_aggcBs eZdZejZdZRS(ssupport for the ARRAY_AGG function. The ``func.array_agg(expr)`` construct returns an expression of type :class:`.types.ARRAY`. e.g.:: stmt = select([func.array_agg(table.c.values)[2:5]]) .. versionadded:: 1.1 .. seealso:: :func:`.postgresql.array_agg` - PostgreSQL-specific version that returns :class:`.postgresql.ARRAY`, which has PG-specific operators added. cOsg|D]}t|^q}|jdtj}d|kr~t|}t|tjrk||dtdefault_array_typettype_from_args((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR@s    (RsRtRuRRqRkR@(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRps t OrderedSetAggcBseZdZeZdZRS(sDefine a function where the return type is based on the sort expression type as defined by the expression passed to the :meth:`.FunctionElement.within_group` method.cCs_|jj}tj|j}|jrPt|jdkrPtj |dj S|dj SdS(Nii( R:RItsqlutiltunwrap_order_byRKtarray_for_multi_clauseRR<RRqRk(R;ROt func_clausesRK((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR]s  (RsRtRuRwRR](((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRstmodecBseZdZRS(s*implement the ``mode`` ordered-set aggregate function. This function must be used with the :meth:`.FunctionElement.within_group` modifier to supply a sort expression to operate upon. The return type of this function is the same as the sort expression. .. versionadded:: 1.1 (RsRtRu(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRs tpercentile_contcBseZdZeZRS(simplement the ``percentile_cont`` ordered-set aggregate function. This function must be used with the :meth:`.FunctionElement.within_group` modifier to supply a sort expression to operate upon. The return type of this function is the same as the sort expression, or if the arguments are an array, an :class:`.types.ARRAY` of the sort expression's type. .. versionadded:: 1.1 (RsRtRuR8R(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRs tpercentile_disccBseZdZeZRS(simplement the ``percentile_disc`` ordered-set aggregate function. This function must be used with the :meth:`.FunctionElement.within_group` modifier to supply a sort expression to operate upon. The return type of this function is the same as the sort expression, or if the arguments are an array, an :class:`.types.ARRAY` of the sort expression's type. .. versionadded:: 1.1 (RsRtRuR8R(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRs trankcBseZdZejZRS(s!Implement the ``rank`` hypothetical-set aggregate function. This function must be used with the :meth:`.FunctionElement.within_group` modifier to supply a sort expression to operate upon. The return type of this function is :class:`.Integer`. .. versionadded:: 1.1 (RsRtRuRRRk(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRs t dense_rankcBseZdZejZRS(s'Implement the ``dense_rank`` hypothetical-set aggregate function. This function must be used with the :meth:`.FunctionElement.within_group` modifier to supply a sort expression to operate upon. The return type of this function is :class:`.Integer`. .. versionadded:: 1.1 (RsRtRuRRRk(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRs t percent_rankcBseZdZejZRS(s)Implement the ``percent_rank`` hypothetical-set aggregate function. This function must be used with the :meth:`.FunctionElement.within_group` modifier to supply a sort expression to operate upon. The return type of this function is :class:`.Numeric`. .. versionadded:: 1.1 (RsRtRuRtNumericRk(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRs t cume_distcBseZdZejZRS(s&Implement the ``cume_dist`` hypothetical-set aggregate function. This function must be used with the :meth:`.FunctionElement.within_group` modifier to supply a sort expression to operate upon. The return type of this function is :class:`.Numeric`. .. versionadded:: 1.1 (RsRtRuRRRk(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRs tcubecBseZdZeZRS(sNImplement the ``CUBE`` grouping operation. This function is used as part of the GROUP BY of a statement, e.g. :meth:`.Select.group_by`:: stmt = select( [func.sum(table.c.value), table.c.col_1, table.c.col_2] ).group_by(func.cube(table.c.col_1, table.c.col_2)) .. versionadded:: 1.2 (RsRtRuR8R5(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyRs trollupcBseZdZeZRS(sNImplement the ``ROLLUP`` grouping operation. This function is used as part of the GROUP BY of a statement, e.g. :meth:`.Select.group_by`:: stmt = select( [func.sum(table.c.value), table.c.col_1, table.c.col_2] ).group_by(func.rollup(table.c.col_1, table.c.col_2)) .. versionadded:: 1.2 (RsRtRuR8R5(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR s t grouping_setscBseZdZeZRS(s%Implement the ``GROUPING SETS`` grouping operation. This function is used as part of the GROUP BY of a statement, e.g. :meth:`.Select.group_by`:: stmt = select( [func.sum(table.c.value), table.c.col_1, table.c.col_2] ).group_by(func.grouping_sets(table.c.col_1, table.c.col_2)) In order to group by multiple sets, use the :func:`.tuple_` construct:: from sqlalchemy import tuple_ stmt = select( [ func.sum(table.c.value), table.c.col_1, table.c.col_2, table.c.col_3] ).group_by( func.grouping_sets( tuple_(table.c.col_1, table.c.col_2), tuple_(table.c.value, table.c.col_3), ) ) .. versionadded:: 1.2 (RsRtRuR8R5(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyR0sN(SRuRRRRRRRtbaseRRtelementsRRR R R R R RRRRRRRt selectableRRRtvisitorsRRRR!R"tsymbolR$R1R2RRtobjectRRRwtmodifierRRtwith_metaclassRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR(((sK/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/functions.pyt s   B=&0 F+"Q   %