
    ,hI                    	   % S r SSKJr  SSKrSSKrSSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r   SSKJ!r!  SSKJ"r"  SSKJ#r#  SSKJ$r$  SS K%J&r&  SS!K%J'r'  SS"K%J(r(  SS#K%J)r)  SS$K%J*r*  SS%K%J+r+  SS&K%J,r,  SS'K%J-r-  SS(K%J.r.  SS)K%J/r/  SS*K%J0r0  SS+K%J1r1  SS,K%J2r2  SS-K3J4r4  SS.K3J5r5  SS/K3J6r6  SS0KJ7r7  SS1KJ8r8  SS2K9J:r:  S3SKJr  \(       a`  SS4KJ;r;  SS5KJ<r<  SS6KJ=r=  SS7KJ>r>  SS8KJ?r?  SS9KJ@r@  SS:KJArA  SS;K%JBrB  SS<K%JCrC  SS=K%JDrD  SS>KJErE  S3S?KFJGrG  S3S@KHJIrI  S3SAKJJKrK  S3SBKJJLrL  S3SCKMJNrN  \" SD\SE9rO\" SF\SE9rP\R                  " \R5      rSSG\TSH'    S       SSI jjrU " SJ SK\"\+\O   \4\#5      rV " SL SM\'\   5      rW " SN SO\0\O   5      rX " SP SQ5      rY\Y" 5       rZ\YR                   \Zl         \Y" SRSS9r[ " ST SU\V\O   5      r\ " SV SW\\\O   5      r]\U" SX\)5        \U" SY\,5         " SZ S[\]\^   5      r_ " S\ S]\]\O   5      r` " S^ S_\]\O   5      ra " S` Sa\a\O   5      rb " Sb Sc\a\O   5      rc " Sd Se\a\O   5      rd " Sf Sg\a\O   5      re " Sh Si\]\R                     5      rf " Sj Sk\]\g   5      rh " Sl Sm\]\^   5      ri " Sn So\]\j   5      rk " Sp Sq\]\^   5      rl " Sr Ss\`\R                     5      rn " St Su\`\R                     5      rp " Sv Sw\`\R                     5      rq " Sx Sy\`\g   5      rr " Sz S{\`\R                     5      rs " S| S}\`\R                     5      rt " S~ S\`\g   5      ru " S S\`\R                     5      rv " S S\`\g   5      rw " S S\a\\O      5      rx " S S\]\O   5      ry " S S\y\O   5      rz " S S\y\O   5      r{ " S S\y\O   5      r| " S S\]\^   5      r} " S S\]\^   5      r~ " S S\]\R                     5      r " S S\]\R                     5      r " S S\]\O   5      r " S S\]\O   5      r " S S\]\O   5      r " S S\]\g   5      rg)z4SQL function API, factories, and built-in functions.    )annotationsN)Any)cast)Dict)List)Mapping)Optional)overload)Sequence)Tuple)Type)TYPE_CHECKING)TypeVar)Union   )
annotation)	coercions)	operators)roles)schema)sqltypes)type_api)util)is_table_value_type)_entity_namespace)ColumnCollection)
Executable)
Generative)HasMemoized)_type_from_args)BinaryExpression)BindParameter)Cast)
ClauseList)ColumnElement)ExtractFunctionFilter)Grouping)literal_column)NamedColumnOverWithinGroup)
FromClause)Select)TableValuedAlias)TableValueType)
TypeEngine)InternalTraversal   )_ByArgument)_ColumnExpressionArgument)"_ColumnExpressionOrLiteralArgument)#_ColumnExpressionOrStrLabelArgument)
_StarOrOne)_TypeEngineArgument)_EntityNamespace)ClauseElement)KeyedColumnElement)TableValuedColumn)OperatorType)
Connection)CursorResult)_CoreMultiExecuteParams)CoreExecuteOptionsParameter)Self_T)bound_Sz5util.defaultdict[str, Dict[str, Type[Function[Any]]]]	_registryc                    [         U   n[        U 5      R                  5       n X;   a%  [        R                  " SR                  U 5      5        XU '   g)zAssociate a callable with a particular func. name.

This is normally called by GenericFunction, but is also
available by itself so that a non-Function construct
can be associated with the :data:`.func` accessor (i.e.
CAST, EXTRACT).

zMThe GenericFunction '{}' is already registered and is going to be overridden.N)rJ   strlowerr   warnformat)
identifierfnpackageregs       P/var/www/auris/envauris/lib/python3.13/site-packages/sqlalchemy/sql/functions.pyregister_functionrU   Z   sL     G
CZ&&(J 		))/
);	
 
O    c                  &  ^  \ rS rSr% SrS\R                  4S\R                  4S\R                  4/r	Sr
S\S'   S	rS	rS
rS\S'   S\S'   S\S'   S\S'       S*S jrS
r\S+U 4S jj5       r        S,S jr S-     S.S jjr      S/S jr S0     S1S jjr\R0                  S2S j5       r\R4                  S2S j5       r\S3S j5       r\  S2S j5       r\R>                  S4S j5       r S
S
S
S
S
S.           S5S jjr!    S6S jr"\#S7S j5       r$\#      S8S j5       r$    S9S  jr$      S:S! jr%\S+S" j5       r&    S;S# jr' S0     S<S$ jjr(S=S% jr)  S0           S>S& jjr*S-S?U 4S' jjjr+\S@S( j5       r,S)r-U =r.$ )AFunctionElementr   ah  Base for SQL function-oriented constructs.

This is a `generic type <https://peps.python.org/pep-0484/#generics>`_,
meaning that type checkers and IDEs can be instructed on the types to
expect in a :class:`_engine.Result` for this function. See
:class:`.GenericFunction` for an example of how this is done.

.. seealso::

    :ref:`tutorial_functions` - in the :ref:`unified_tutorial`

    :class:`.Function` - named SQL function.

    :data:`.func` - namespace which produces registered or ad-hoc
    :class:`.Function` instances.

    :class:`.GenericFunction` - allows creation of registered function
    types.

clause_expr_with_ordinality_table_value_type zTuple[str, ...]packagenamesFNzOptional[TableValueType]r   primary_key_is_clone_ofzGrouping[Any]c                $   U Vs/ s H3  n[         R                  " [        R                  U[	        U SS5      U S9PM5     nnU R
                  =(       d    [        U5      U l        [        [        U[        R                  SS.65      U l        gs  snf )a  Construct a :class:`.FunctionElement`.

:param \*clauses: list of column expressions that form the arguments
 of the SQL function call.

:param \**kwargs:  additional kwargs are typically consumed by
 subclasses.

.. seealso::

    :data:`.func`

    :class:`.Function`

nameNrb   apply_propagate_attrsToperatorgroup_contents)r   expectr   ExpressionElementRolegetattr	_has_argsboolr)   r$   r   comma_oprZ   )selfclausescargss       rT   __init__FunctionElement.__init__   s    2 :
  ++T640&*	  	 :
 54:#$	 2 24O
:
s   :Bc                @   > [         TU ]  =(       d    [        U SS 5      $ )Nrb   )super
_proxy_keyrj   )rn   	__class__s    rT   rv   FunctionElement._proxy_key   s    w!@WT64%@@rV   c                &    UR                  XU5      $ N)_execute_function)rn   
connectiondistilled_paramsexecution_optionss       rT   _execute_on_connection&FunctionElement._execute_on_connection   s     ++$5
 	
rV   c                    [        XU5      $ )a  Return a column expression that's against this
:class:`_functions.FunctionElement` as a scalar
table-valued expression.

The returned expression is similar to that returned by a single column
accessed off of a :meth:`_functions.FunctionElement.table_valued`
construct, except no FROM clause is generated; the function is rendered
in the similar way as a scalar subquery.

E.g.:

.. sourcecode:: pycon+sql

    >>> from sqlalchemy import func, select
    >>> fn = func.jsonb_each("{'k', 'v'}").scalar_table_valued("key")
    >>> print(select(fn))
    {printsql}SELECT (jsonb_each(:jsonb_each_1)).key

.. versionadded:: 1.4.0b2

.. seealso::

    :meth:`_functions.FunctionElement.table_valued`

    :meth:`_functions.FunctionElement.alias`

    :meth:`_functions.FunctionElement.column_valued`

)ScalarFunctionColumn)rn   rb   type_s      rT   scalar_table_valued#FunctionElement.scalar_table_valued   s    B $D66rV   c                    U R                  5       nUR                  SS5      nUR                  SS5      nUR                  SS5      nU(       a  X4-  nSUl        [        U6 =Ul        Ul        UR                  XeS9$ )aP
  Return a :class:`_sql.TableValuedAlias` representation of this
:class:`_functions.FunctionElement` with table-valued expressions added.

e.g.:

.. sourcecode:: pycon+sql

    >>> fn = func.generate_series(1, 5).table_valued(
    ...     "value", "start", "stop", "step"
    ... )

    >>> print(select(fn))
    {printsql}SELECT anon_1.value, anon_1.start, anon_1.stop, anon_1.step
    FROM generate_series(:generate_series_1, :generate_series_2) AS anon_1{stop}

    >>> print(select(fn.c.value, fn.c.stop).where(fn.c.value > 2))
    {printsql}SELECT anon_1.value, anon_1.stop
    FROM generate_series(:generate_series_1, :generate_series_2) AS anon_1
    WHERE anon_1.value > :value_1{stop}

A WITH ORDINALITY expression may be generated by passing the keyword
argument "with_ordinality":

.. sourcecode:: pycon+sql

    >>> fn = func.generate_series(4, 1, -1).table_valued(
    ...     "gen", with_ordinality="ordinality"
    ... )
    >>> print(select(fn))
    {printsql}SELECT anon_1.gen, anon_1.ordinality
    FROM generate_series(:generate_series_1, :generate_series_2, :generate_series_3) WITH ORDINALITY AS anon_1

:param \*expr: A series of string column names that will be added to the
 ``.c`` collection of the resulting :class:`_sql.TableValuedAlias`
 construct as columns.  :func:`_sql.column` objects with or without
 datatypes may also be used.

:param name: optional name to assign to the alias name that's generated.
 If omitted, a unique anonymizing name is used.

:param with_ordinality: string name that when present results in the
 ``WITH ORDINALITY`` clause being added to the alias, and the given
 string name will be added as a column to the .c collection
 of the resulting :class:`_sql.TableValuedAlias`.

:param joins_implicitly: when True, the table valued function may be
 used in the FROM clause without any explicit JOIN to other tables
 in the SQL query, and no "cartesian product" warning will be generated.
 May be useful for SQL functions such as ``func.json_each()``.

 .. versionadded:: 1.4.33

.. versionadded:: 1.4.0b2


.. seealso::

    :ref:`tutorial_functions_table_valued` - in the :ref:`unified_tutorial`

    :ref:`postgresql_table_valued` - in the :ref:`postgresql_toplevel` documentation

    :meth:`_functions.FunctionElement.scalar_table_valued` - variant of
    :meth:`_functions.FunctionElement.table_valued` which delivers the
    complete table valued expression as a scalar column expression

    :meth:`_functions.FunctionElement.column_valued`

    :meth:`_sql.TableValuedAlias.render_derived` - renders the alias
    using a derived column clause, e.g. ``AS name(col1, col2, ...)``

with_ordinalityNjoins_implicitlyrb   Trb   r   )	_generatepopr[   r3   typer\   alias)rn   exprkwnew_funcr   r   rb   s          rT   table_valuedFunctionElement.table_valued   s    V >>#&&!2D966"4d;vvfd#&&D(,H%5CT5JJ2~~4~KKrV   c                4    U R                  XS9R                  $ )a  Return this :class:`_functions.FunctionElement` as a column expression that
selects from itself as a FROM clause.

E.g.:

.. sourcecode:: pycon+sql

    >>> from sqlalchemy import select, func
    >>> gs = func.generate_series(1, 5, -1).column_valued()
    >>> print(select(gs))
    {printsql}SELECT anon_1
    FROM generate_series(:generate_series_1, :generate_series_2, :generate_series_3) AS anon_1

This is shorthand for::

    gs = func.generate_series(1, 5, -1).alias().column

:param name: optional name to assign to the alias name that's generated.
 If omitted, a unique anonymizing name is used.

:param joins_implicitly: when True, the "table" portion of the column
 valued function may be a member of the FROM clause without any
 explicit JOIN to other tables in the SQL query, and no "cartesian
 product" warning will be generated. May be useful for SQL functions
 such as ``func.json_array_elements()``.

 .. versionadded:: 1.4.46

.. seealso::

    :ref:`tutorial_functions_column_valued` - in the :ref:`unified_tutorial`

    :ref:`postgresql_column_valued` - in the :ref:`postgresql_toplevel` documentation

    :meth:`_functions.FunctionElement.table_valued`

r   )r   columnrn   rb   r   s      rT   column_valuedFunctionElement.column_valuedG  s    R zztzGNNNrV   c                    U R                   $ )a  The set of columns exported by this :class:`.FunctionElement`.

This is a placeholder collection that allows the function to be
placed in the FROM clause of a statement:

.. sourcecode:: pycon+sql

    >>> from sqlalchemy import column, select, func
    >>> stmt = select(column("x"), column("y")).select_from(func.myfunction())
    >>> print(stmt)
    {printsql}SELECT x, y FROM myfunction()

The above form is a legacy feature that is now superseded by the
fully capable :meth:`_functions.FunctionElement.table_valued`
method; see that method for details.

.. seealso::

    :meth:`_functions.FunctionElement.table_valued` - generates table-valued
    SQL function expressions.

)rp   rn   s    rT   columnsFunctionElement.columnsr  s    0 vvrV   c                j    [        U R                   Vs/ s H  oR                  U4PM     snS9$ s  snf )z-synonym for :attr:`.FunctionElement.columns`.r   )r   _all_selected_columnskey)rn   cols     rT   rp   FunctionElement.c  s4      /3/I/IJ/Iggs^/IJ
 	
Js   0c                    [        U R                  5      (       a"  [        SU R                  R                  5      nU$ U R	                  S 5      /nU$ )N!Sequence[KeyedColumnElement[Any]])r   r   r   	_elementslabel)rn   colss     rT   r   %FunctionElement._all_selected_columns  sI    tyy))3TYY5H5HD  JJt$%DrV   c                    U R                   $ rz   r   r   s    rT   exported_columns FunctionElement.exported_columns  s     ||rV   c                J    [        [        U R                  R                  5      $ )zmReturn the underlying :class:`.ClauseList` which contains
the arguments for this :class:`.FunctionElement`.

)r   r$   rZ   elementr   s    rT   ro   FunctionElement.clauses  s     J 0 0 8 899rV   partition_byorder_byrowsrange_groupsc          	         [        U UUUUUS9$ )a  Produce an OVER clause against this function.

Used against aggregate or so-called "window" functions,
for database backends that support window functions.

The expression::

    func.row_number().over(order_by="x")

is shorthand for::

    from sqlalchemy import over

    over(func.row_number(), order_by="x")

See :func:`_expression.over` for a full description.

.. seealso::

    :func:`_expression.over`

    :ref:`tutorial_window_functions` - in the :ref:`unified_tutorial`

r   r,   )rn   r   r   r   r   r   s         rT   overFunctionElement.over  s$    B %
 	
rV   c                    [        U /UQ76 $ )a  Produce a WITHIN GROUP (ORDER BY expr) clause against this function.

Used against so-called "ordered set aggregate" and "hypothetical
set aggregate" functions, including :class:`.percentile_cont`,
:class:`.rank`, :class:`.dense_rank`, etc.

See :func:`_expression.within_group` for a full description.

.. seealso::

    :ref:`tutorial_functions_within_group` -
    in the :ref:`unified_tutorial`


r.   )rn   r   s     rT   within_groupFunctionElement.within_group  s    $ 4+(++rV   c                    g rz   r]   r   s    rT   filterFunctionElement.filter  s    !rV   c                    g rz   r]   )rn   _FunctionElement__criterion0	criterions      rT   r   r     s    
 !rV   c                ,    U(       d  U $ [        U /UQ76 $ )a  Produce a FILTER clause against this function.

Used against aggregate and window functions,
for database backends that support the "FILTER" clause.

The expression::

    func.count(1).filter(True)

is shorthand for::

    from sqlalchemy import funcfilter

    funcfilter(func.count(1), True)

.. seealso::

    :ref:`tutorial_functions_within_group` -
    in the :ref:`unified_tutorial`

    :class:`.FunctionFilter`

    :func:`.funcfilter`


r'   )rn   r   s     rT   r   r     s    : Kd/Y//rV   c                    [        XU5      $ )a	  Interpret this expression as a boolean comparison between two
values.

This method is used for an ORM use case described at
:ref:`relationship_custom_operator_sql_function`.

A hypothetical SQL function "is_equal()" which compares to values
for equality would be written in the Core expression language as::

    expr = func.is_equal("a", "b")

If "is_equal()" above is comparing "a" and "b" for equality, the
:meth:`.FunctionElement.as_comparison` method would be invoked as::

    expr = func.is_equal("a", "b").as_comparison(1, 2)

Where above, the integer value "1" refers to the first argument of the
"is_equal()" function and the integer value "2" refers to the second.

This would create a :class:`.BinaryExpression` that is equivalent to::

    BinaryExpression("a", "b", operator=op.eq)

However, at the SQL level it would still render as
"is_equal('a', 'b')".

The ORM, when it loads a related object or collection, needs to be able
to manipulate the "left" and "right" sides of the ON clause of a JOIN
expression. The purpose of this method is to provide a SQL function
construct that can also supply this information to the ORM, when used
with the :paramref:`_orm.relationship.primaryjoin` parameter. The
return value is a containment object called :class:`.FunctionAsBinary`.

An ORM example is as follows::

    class Venue(Base):
        __tablename__ = "venue"
        id = Column(Integer, primary_key=True)
        name = Column(String)

        descendants = relationship(
            "Venue",
            primaryjoin=func.instr(
                remote(foreign(name)), name + "/"
            ).as_comparison(1, 2)
            == 1,
            viewonly=True,
            order_by=name,
        )

Above, the "Venue" class can load descendant "Venue" objects by
determining if the name of the parent Venue is contained within the
start of the hypothetical descendant value's name, e.g. "parent1" would
match up to "parent1/child1", but not to "parent2/child1".

Possible use cases include the "materialized path" example given above,
as well as making use of special SQL functions such as geometric
functions to create join conditions.

:param left_index: the integer 1-based index of the function argument
 that serves as the "left" side of the expression.
:param right_index: the integer 1-based index of the function argument
 that serves as the "right" side of the expression.

.. versionadded:: 1.3

.. seealso::

    :ref:`relationship_custom_operator_sql_function` -
    example use within the ORM

)FunctionAsBinary)rn   
left_indexright_indexs      rT   as_comparisonFunctionElement.as_comparison  s    V  +>>rV   c                .    U R                   R                  $ rz   )ro   _from_objectsr   s    rT   r   FunctionElement._from_objectsd  s    ||)))rV   c                    g)zFor types that define their return type as based on the criteria
within a WITHIN GROUP (ORDER BY) expression, called by the
:class:`.WithinGroup` construct.

Returns None by default, in which case the function's normal ``.type``
is used.

Nr]   )rn   r   s     rT   within_group_type!FunctionElement.within_group_typeh  s     rV   c                D    [         R                  " U UU R                  US9$ )a  Produce a :class:`_expression.Alias` construct against this
:class:`.FunctionElement`.

.. tip::

    The :meth:`_functions.FunctionElement.alias` method is part of the
    mechanism by which "table valued" SQL functions are created.
    However, most use cases are covered by higher level methods on
    :class:`_functions.FunctionElement` including
    :meth:`_functions.FunctionElement.table_valued`, and
    :meth:`_functions.FunctionElement.column_valued`.

This construct wraps the function in a named alias which
is suitable for the FROM clause, in the style accepted for example
by PostgreSQL.  A column expression is also provided using the
special ``.column`` attribute, which may
be used to refer to the output of the function as a scalar value
in the columns or where clause, for a backend such as PostgreSQL.

For a full table-valued expression, use the
:meth:`_functions.FunctionElement.table_valued` method first to
establish named columns.

e.g.:

.. sourcecode:: pycon+sql

    >>> from sqlalchemy import func, select, column
    >>> data_view = func.unnest([1, 2, 3]).alias("data_view")
    >>> print(select(data_view.column))
    {printsql}SELECT data_view
    FROM unnest(:unnest_1) AS data_view

The :meth:`_functions.FunctionElement.column_valued` method provides
a shortcut for the above pattern:

.. sourcecode:: pycon+sql

    >>> data_view = func.unnest([1, 2, 3]).column_valued("data_view")
    >>> print(select(data_view))
    {printsql}SELECT data_view
    FROM unnest(:unnest_1) AS data_view

.. versionadded:: 1.4.0b2  Added the ``.column`` accessor

:param name: alias name, will be rendered as ``AS <name>`` in the
 FROM clause

:param joins_implicitly: when True, the table valued function may be
 used in the FROM clause without any explicit JOIN to other tables
 in the SQL query, and no "cartesian product" warning will be
 generated.  May be useful for SQL functions such as
 ``func.json_each()``.

 .. versionadded:: 1.4.33

.. seealso::

    :ref:`tutorial_functions_table_valued` -
    in the :ref:`unified_tutorial`

    :meth:`_functions.FunctionElement.table_valued`

    :meth:`_functions.FunctionElement.scalar_table_valued`

    :meth:`_functions.FunctionElement.column_valued`


)rb   table_value_typer   )r2   
_constructr   r   s      rT   r   FunctionElement.aliasv  s(    R  **!YY-	
 	
rV   c                v    [        U 5      nU R                  (       a  UR                  " S0 U R                  D6nU$ )zProduce a :func:`_expression.select` construct
against this :class:`.FunctionElement`.

This is shorthand for::

    s = select(function_element)

r]   )r1   _execution_optionsr~   )rn   ss     rT   selectFunctionElement.select  s4      ""##>d&=&=>ArV   c           	     <    [        S U4UU R                  SUUS.UD6$ )NT)_compared_to_operator_compared_to_typeuniquer   	expanding)r"   r   rn   rf   objr   r   r   s         rT   _bind_paramFunctionElement._bind_param  s;     	
 #+"ii	
 	
 		
rV   c                   > U[         R                  L a4  [        U R                  [        R
                  5      (       a  [        U 5      $ [        TU ]!  US9$ )N)against)	r   getitem
isinstancer   r   ARRAYr)   ru   
self_group)rn   r   rw   s     rT   r   FunctionElement.self_group  sK    
 i'''JIIx~~-
 -
 D>!7%g%66rV   c                ,    [        U R                  5      $ )zjoverrides FromClause.entity_namespace as functions are generally
column expressions and not FromClauses.

)r   rZ   r   s    rT   entity_namespace FunctionElement.entity_namespace  s     !!1!122rV   )rk   rZ   )ro   '_ColumnExpressionOrLiteralArgument[Any]returnNoner   r   )r|   rB   r}   rD   r~   rE   r   zCursorResult[Any]rz   )rb   rL   r   !Optional[_TypeEngineArgument[_T]]r   zScalarFunctionColumn[_T])r   z(_ColumnExpressionOrStrLabelArgument[Any]r   r   r   r2   NF)rb   Optional[str]r   rl   r   zTableValuedColumn[_T])r   z.ColumnCollection[str, KeyedColumnElement[Any]])r   r   )r   r$   )r   Optional[_ByArgument]r   r   r   -Optional[Tuple[Optional[int], Optional[int]]]r   r   r   r   r   zOver[_T])r   _ColumnExpressionArgument[Any]r   zWithinGroup[_T])r   rF   )r   _ColumnExpressionArgument[bool]r   r   r   zFunctionFilter[_T])r   r   r   zUnion[Self, FunctionFilter[_T]])r   intr   r   r   r   )r   zWithinGroup[_S]r   zOptional[TypeEngine[_S]])rb   r   r   rl   r   r2   )r   zSelect[Tuple[_T]]rf   rA   r   r   r   zOptional[TypeEngine[_T]]r   rl   r   r   r   zBindParameter[_T])r   zOptional[OperatorType]r   r>   )r   r=   )/__name__
__module____qualname____firstlineno____doc__r5   dp_clauseelement
dp_booleandp_has_cache_key_traverse_internalsr^   __annotations__rk   r[   r\   rr   _non_anon_labelpropertyrv   r   r   r   r   r   ro_non_memoized_propertyr   ro_memoized_propertyrp   r   r   r   memoized_attributero   r   r   r
   r   r   r   r   r   r   r   r   r   __static_attributes____classcell__rw   s   @rT   rX   rX   r   s^   , 
)::;	.99:	/@@A %'L/&I26/6 
?
	
@ OA A

 2
 7	

 

 EI!7!7 A!7	!!7FWL=WLEHWL	WLt DI)O!)O<@)O	)OV 
"" #2 

 
 	 	 	7 
 ##: $: /3*.>B@D@D(
 ,(
 (	(

 <(
 >(
 >(
 
(
T,7,	,( ! !!5! 4! 
	! !090	(0BK?K?,/K?	K?Z * *+	! DIN
!N
<@N
	N
`$ +/

 
 (	

 
 
 

&
7 
7 3 3rV   rX   c                  X   \ rS rSr% S\R
                  4S\R                  4S\R                  4S\R                  4/rS\	S'   S\	S'   S\	S'   SS jr
        SS	 jr\SS
 j5       r\R                  SS j5       r\SS j5       r\R                  SS j5       r\(       d  \r\rSrgSrg)r   i  sql_functionr   r   	modifiersFunctionElement[Any]r   c                0    [         R                  " XU5      $ rz   )r%   _gen_cache_key)rn   anon_map
bindparamss      rT   r  FunctionAsBinary._gen_cache_key
  s    ++DJGGrV   c                    Xl         X l        X0l        [        R                  U l        [        R                  U l        S U l	        SU l
        0 U l        g )NT)r	  r   r   r   function_as_comparison_oprf   r   BOOLEANTYPEr   negate_is_implicitly_booleanr
  )rn   rQ   r   r   s       rT   rr   FunctionAsBinary.__init__  sE     $&!;;((	&*#rV   c                b    U R                   R                  R                  U R                  S-
     $ Nr   r	  ro   r   r   s    rT   	left_exprFunctionAsBinary.left_expr  s(      ((0011DEErV   c                b    XR                   R                  R                  U R                  S-
  '   g r  r  rn   values     rT   r  r    s%    AF!!))$//A*=>rV   c                b    U R                   R                  R                  U R                  S-
     $ r  r	  ro   r   r   s    rT   
right_exprFunctionAsBinary.right_expr"  s*      ((001A1AA1EFFrV   c                b    XR                   R                  R                  U R                  S-
  '   g r  r   r  s     rT   r!  r"  &  s'    BG!!))$*:*:Q*>?rV   )r  r   r
  r  rf   r   r	  r   N)r  r   r  r   r   r   )rQ   r  r   r   r   r   r   r   )r   ColumnElement[Any])r  r$  r   r   )r   r   r   r   r5   r   dp_plain_objdp_plain_dictr   r   r  rr   r  r  setterr!  r   leftrightr  r]   rV   rT   r   r     s    	*;;<	(556	)667	'556	 '&OH&47FI	 F F G G G G H H   rV   r   c                      \ rS rSrSrS\R                  4S\R                  4S\R                  4/r	Sr
Sr S
       SS jjrS	rg)r   i2  scalar_function_columnrb   r   rQ   FNc                R    Xl         X l        [        R                  " U5      U l        g rz   )rQ   rb   r   to_instancer   )rn   rQ   rb   r   s       rT   rr   ScalarFunctionColumn.__init__>  s"     	 ((/	rV   )rQ   rb   r   rz   )rQ   zFunctionElement[_T]rb   rL   r   r   r   r   )r   r   r   r   __visit_name__r5   dp_anon_namedp_typer   r   
is_literaltablerr   r  r]   rV   rT   r   r   2  s    -N 
"//0	"**+	 112 JE 48	00 0 1	0
 
0 0rV   r   c                  z   \ rS rSrSrS<S jrS=S jr\        S>S j5       r\S?S j5       rS?S jr\	(       Ga~  \
S@S j5       r\
SAS	 j5       r\        SBS
 j5       r\        SCS j5       r\        SDS j5       r        SES jr\
SFS j5       r\
SGS j5       r\        SHS j5       r\        SIS j5       r\        SJS j5       r        SKS jr\
SLS j5       r\
SMS j5       r\
SNS j5       r\
SOS j5       r\
SPS j5       r\
SQS j5       r\
SRS j5       r\
SSS j5       r\
STS j5       r\
SUS j5       r\
SVS j5       r\
SWS j5       r\
SXS  j5       r\        SYS! j5       r\        SZS" j5       r\        S[S# j5       r        S\S$ jr\        S]S% j5       r\        S^S& j5       r\        S_S' j5       r        S`S( jr\
SaS) j5       r \
SbS* j5       r!\
ScS+ j5       r"\
SdS, j5       r#\
SeS- j5       r$\
SfS. j5       r%\
SgS/ j5       r&\
ShS0 j5       r'\
SiS1 j5       r(\
SjS2 j5       r)\
SkS3 j5       r*\        SlS4 j5       r+\        SmS5 j5       r+\        SnS6 j5       r+        SoS7 jr+\
SpS8 j5       r,\
SqS9 j5       r-S:r.g;S:r.g;)r_FunctionGeneratoriL  a  Generate SQL function expressions.

:data:`.func` is a special object instance which generates SQL
functions based on name-based attributes, e.g.:

.. sourcecode:: pycon+sql

    >>> print(func.count(1))
    {printsql}count(:param_1)

The returned object is an instance of :class:`.Function`, and  is a
column-oriented SQL element like any other, and is used in that way:

.. sourcecode:: pycon+sql

    >>> print(select(func.count(table.c.id)))
    {printsql}SELECT count(sometable.id) FROM sometable

Any name can be given to :data:`.func`. If the function name is unknown to
SQLAlchemy, it will be rendered exactly as is. For common SQL functions
which SQLAlchemy is aware of, the name may be interpreted as a *generic
function* which will be compiled appropriately to the target database:

.. sourcecode:: pycon+sql

    >>> print(func.current_timestamp())
    {printsql}CURRENT_TIMESTAMP

To call functions which are present in dot-separated packages,
specify them in the same manner:

.. sourcecode:: pycon+sql

    >>> print(func.stats.yield_curve(5, 10))
    {printsql}stats.yield_curve(:yield_curve_1, :yield_curve_2)

SQLAlchemy can be made aware of the return type of functions to enable
type-specific lexical and result-based behavior. For example, to ensure
that a string-based function returns a Unicode value and is similarly
treated as a string in expressions, specify
:class:`~sqlalchemy.types.Unicode` as the type:

.. sourcecode:: pycon+sql

    >>> print(
    ...     func.my_string("hi", type_=Unicode)
    ...     + " "
    ...     + func.my_string("there", type_=Unicode)
    ... )
    {printsql}my_string(:my_string_1) || :my_string_2 || my_string(:my_string_3)

The object returned by a :data:`.func` call is usually an instance of
:class:`.Function`.
This object meets the "column" interface, including comparison and labeling
functions.  The object can also be passed the :meth:`~.Connectable.execute`
method of a :class:`_engine.Connection` or :class:`_engine.Engine`,
where it will be
wrapped inside of a SELECT statement first::

    print(connection.execute(func.current_timestamp()).scalar())

In a few exception cases, the :data:`.func` accessor
will redirect a name to a built-in expression such as :func:`.cast`
or :func:`.extract`, as these names have well-known meaning
but are not exactly the same as "functions" from a SQLAlchemy
perspective.

Functions which are interpreted as "generic" functions know how to
calculate their return type automatically. For a listing of known generic
functions, see :ref:`generic_functions`.

.. note::

    The :data:`.func` construct has only limited support for calling
    standalone "stored procedures", especially those with special
    parameterization concerns.

    See the section :ref:`stored_procedures` for details on how to use
    the DBAPI-level ``callproc()`` method for fully traditional stored
    procedures.

.. seealso::

    :ref:`tutorial_functions` - in the :ref:`unified_tutorial`

    :class:`.Function`

c                    / U l         Xl        g rz   )_FunctionGenerator__namesopts)rn   r8  s     rT   rr   _FunctionGenerator.__init__  s    "$	rV   c                    UR                  S5      (       a   U R                  U   $ UR	                  S5      (       a  USS n[        S0 U R                  D6n[        U R                  5      U/-   Ul        U$ ! [         a    [        U5      ef = f)N___r   r]   )	
startswith__dict__KeyErrorAttributeErrorendswithr5  r8  listr7  )rn   rb   fs      rT   __getattr___FunctionGenerator.__getattr__  s    ??4  +}}T** ]]3":D++&$/	  +$T**+s   A7 7Bc                   g rz   r]   )rn   r   rp   kwargss       rT   __call___FunctionGenerator.__call__  s     rV   c                    g rz   r]   )rn   rp   rH  s      rT   rI  rJ        ADrV   c           	        U R                   R                  5       nUR                  U5        [        U R                  5      nUS:X  a  U R                  u  pVOUS:X  a  SU R                  S   peOS nUb1  [
        U   R                  WR                  5       5      nUb  U" U0 UD6$ [        U R                  S   /UQ7S[        U R                  SS 5      0UD6$ )Nr6   r   _defaultr   r=  r^   )
r8  copyupdatelenr7  rJ   getrM   Functiontuple)rn   rp   rH  otokensrR   fnamefuncs           rT   rI  rJ    s    IINN	T\\"Q;!\\NGUq['aUGW%))%++-8DQ}!}$LL
GH
+0a1C+D
LM
 	
rV   c                    g rz   r]   r   s    rT   aggregate_strings$_FunctionGenerator.aggregate_strings      @CrV   c                    g rz   r]   r   s    rT   ansifunction_FunctionGenerator.ansifunction  s    ;>rV   c                    g rz   r]   rn   r   rq   rH  s       rT   	array_agg_FunctionGenerator.array_agg        rV   c                    g rz   r]   ra  s       rT   rb  rc    rd  rV   c                    g rz   r]   ra  s       rT   rb  rc    rd  rV   c                    g rz   r]   ra  s       rT   rb  rc    s    
  rV   c                    g rz   r]   r   s    rT   r   _FunctionGenerator.cast      +.rV   c                    g rz   r]   r   s    rT   char_length_FunctionGenerator.char_length	  s    47rV   c                    g rz   r]   ra  s       rT   coalesce_FunctionGenerator.coalesce       rV   c                    g rz   r]   ra  s       rT   ro  rp    rq  rV   c                    g rz   r]   ra  s       rT   ro  rp  !  rq  rV   c                    g rz   r]   ra  s       rT   ro  rp  )  s    
 rV   c                    g rz   r]   r   s    rT   concat_FunctionGenerator.concat0      *-rV   c                    g rz   r]   r   s    rT   count_FunctionGenerator.count3  s    (+rV   c                    g rz   r]   r   s    rT   cube_FunctionGenerator.cube6  rj  rV   c                    g rz   r]   r   s    rT   	cume_dist_FunctionGenerator.cume_dist9      03rV   c                    g rz   r]   r   s    rT   current_date_FunctionGenerator.current_date<      69rV   c                    g rz   r]   r   s    rT   current_time_FunctionGenerator.current_time?  r  rV   c                    g rz   r]   r   s    rT   current_timestamp$_FunctionGenerator.current_timestampB  r\  rV   c                    g rz   r]   r   s    rT   current_user_FunctionGenerator.current_userE  r  rV   c                    g rz   r]   r   s    rT   
dense_rank_FunctionGenerator.dense_rankH      25rV   c                    g rz   r]   r   s    rT   extract_FunctionGenerator.extractK      ,/rV   c                    g rz   r]   r   s    rT   grouping_sets _FunctionGenerator.grouping_setsN      =@rV   c                    g rz   r]   r   s    rT   	localtime_FunctionGenerator.localtimeQ  r  rV   c                    g rz   r]   r   s    rT   localtimestamp!_FunctionGenerator.localtimestampT  s    :=rV   c                    g rz   r]   ra  s       rT   max_FunctionGenerator.max\       rV   c                    g rz   r]   ra  s       rT   r  r  d  r  rV   c                    g rz   r]   ra  s       rT   r  r  l  r  rV   c                    g rz   r]   ra  s       rT   r  r  t      
 rV   c                    g rz   r]   ra  s       rT   min_FunctionGenerator.min  r  rV   c                    g rz   r]   ra  s       rT   r  r    r  rV   c                    g rz   r]   ra  s       rT   r  r    r  rV   c                    g rz   r]   ra  s       rT   r  r    r  rV   c                    g rz   r]   r   s    rT   mode_FunctionGenerator.mode  rj  rV   c                    g rz   r]   r   s    rT   
next_value_FunctionGenerator.next_value  r  rV   c                    g rz   r]   r   s    rT   now_FunctionGenerator.now  s    $'rV   c                    g rz   r]   r   s    rT   orderedsetagg _FunctionGenerator.orderedsetagg  r  rV   c                    g rz   r]   r   s    rT   percent_rank_FunctionGenerator.percent_rank  r  rV   c                    g rz   r]   r   s    rT   percentile_cont"_FunctionGenerator.percentile_cont  rL  rV   c                    g rz   r]   r   s    rT   percentile_disc"_FunctionGenerator.percentile_disc  rL  rV   c                    g rz   r]   r   s    rT   random_FunctionGenerator.random  rx  rV   c                    g rz   r]   r   s    rT   rank_FunctionGenerator.rank      &)rV   c                    g rz   r]   r   s    rT   rollup_FunctionGenerator.rollup  s    /2rV   c                    g rz   r]   r   s    rT   session_user_FunctionGenerator.session_user  r  rV   c                    g rz   r]   ra  s       rT   sum_FunctionGenerator.sum  r  rV   c                    g rz   r]   ra  s       rT   r  r    r  rV   c                    g rz   r]   ra  s       rT   r  r    r  rV   c                    g rz   r]   ra  s       rT   r  r    r  rV   c                    g rz   r]   r   s    rT   sysdate_FunctionGenerator.sysdate  r  rV   c                    g rz   r]   r   s    rT   user_FunctionGenerator.user  r  rV   )__namesr8  N)r8  r   r   r   )rb   rL   r   r5  )rp   r   r   _TypeEngineArgument[_T]rH  r   r   zFunction[_T])rp   r   rH  r   r   zFunction[Any])r   zType[aggregate_strings])r   zType[AnsiFunction[Any]])r   ColumnElement[_T]rq   r   rH  r   r   array_agg[_T])r   _ColumnExpressionArgument[_T]rq   r   rH  r   r   r  )r   rG   rq   r   rH  r   r   r  )r   &_ColumnExpressionOrLiteralArgument[_T]rq   r   rH  r   r   r  )r   zType[Cast[Any]])r   zType[char_length])r   r  rq   r   rH  r   r   coalesce[_T])r   r  rq   r   rH  r   r   r  )r   rG   rq   r   rH  r   r   r  )r   r  rq   r   rH  r   r   r  )r   zType[concat])r   zType[count])r   zType[cube[Any]])r   zType[cume_dist])r   zType[current_date])r   zType[current_time])r   zType[current_timestamp])r   zType[current_user])r   zType[dense_rank])r   zType[Extract])r   zType[grouping_sets[Any]])r   zType[localtime])r   zType[localtimestamp])r   r  rq   r   rH  r   r   max[_T])r   r  rq   r   rH  r   r   r  )r   rG   rq   r   rH  r   r   r  )r   r  rq   r   rH  r   r   r  )r   r  rq   r   rH  r   r   min[_T])r   r  rq   r   rH  r   r   r  )r   rG   rq   r   rH  r   r   r  )r   r  rq   r   rH  r   r   r  )r   zType[mode[Any]])r   zType[next_value])r   z	Type[now])r   zType[OrderedSetAgg[Any]])r   zType[percent_rank])r   zType[percentile_cont[Any]])r   zType[percentile_disc[Any]])r   zType[random])r   z
Type[rank])r   zType[rollup[Any]])r   zType[session_user])r   r  rq   r   rH  r   r   sum[_T])r   r  rq   r   rH  r   r   r  )r   rG   rq   r   rH  r   r   r  )r   r  rq   r   rH  r   r   r  )r   zType[sysdate])r   z
Type[user])/r   r   r   r   r   rr   rE  r
   rI  r   r  rZ  r^  rb  r   rl  ro  rv  rz  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r]   rV   rT   r5  r5  L  sR   Wr 5AD	  D D
,  
C 
C	> 
> 
	 "	  ;	  		 
 	  
	  
	 .	  ;	  		 
 	  
	  
	 	  ;	  		 
 	  
	 	 7	  ;	  		 
 	  
. 
.	7 
7 
	"	 ;	 		
 	 
	 
	.	 ;	 		
 	 
	 
		 ;	 		
 	 
		7	 ;	 		
 	 
- 
-	+ 
+	. 
.	3 
3	9 
9	9 
9	C 
C	9 
9	5 
5	/ 
/	@ 
@	3 
3	= 
= 
	"	 ;	 		
 	 
	 
	.	 ;	 		
 	 
	 
		 ;	 		
 	 
		7	 ;	 		
 	 
	"	 ;	 		
 	 
	 
	.	 ;	 		
 	 
	 
		 ;	 		
 	 
		7	 ;	 		
 	 
. 
.	5 
5	' 
'	@ 
@	9 
9	D 
D	D 
D	- 
-	) 
)	2 
2	9 
9 
	"	 ;	 		
 	 
	 
	.	 ;	 		
 	 
	 
		 ;	 		
 	 
		7	 ;	 		
 	 
/ 
/	) 
)e rV   r5  F)groupc                  X   \ rS rSr% SrSr\R                  S\R                  4S\R                  4S\R                  4/-   rS\S'   S\S'   S	\S'    \S
S
S.         SS jj5       r\S
S
S.         SS jj5       rSSS.         SS jjr  S           SS jjrSrg)rS  i  a  Describe a named SQL function.

The :class:`.Function` object is typically generated from the
:data:`.func` generation object.


:param \*clauses: list of column expressions that form the arguments
 of the SQL function call.

:param type\_: optional :class:`.TypeEngine` datatype object that will be
 used as the return value of the column expression generated by this
 function call.

:param packagenames: a string which indicates package prefix names
 to be prepended to the function name when the SQL is generated.
 The :data:`.func` generator creates these when it is called using
 dotted format, e.g.::

    func.mypackage.some_function(col1, col2)

.. seealso::

    :ref:`tutorial_functions` - in the :ref:`unified_tutorial`

    :data:`.func` - namespace which produces registered or ad-hoc
    :class:`.Function` instances.

    :class:`.GenericFunction` - allows creation of registered function
    types.

functionr^   rb   r   rL   rP   zTypeEngine[_T].)r   r^   c                   g rz   r]   rn   rb   r   r^   ro   s        rT   rr   Function.__init__1       rV   c                   g rz   r]   r  s        rT   rr   r  :  r  rV   Nc                   U=(       d    SU l         Xl        [        R                  " U5      U l        [
        R                  " U /UQ76   g)z~Construct a :class:`.Function`.

The :data:`.func` construct is normally used to construct
new :class:`.Function` instances.

r]   N)r^   rb   r   r-  r   rX   rr   r  s        rT   rr   r  C  s=     ).B	 ((/	  00rV   c           	     P    [        U R                  U4UU R                  USUS.UD6$ )NT)r   r   r   r   r   )r"   rb   r   r   s         rT   r   Function._bind_paramY  s?     II	
 #+"ii	
 	
 		
rV   )rb   r^   r   )
rb   rL   ro   r  r   r   r^   Optional[Tuple[str, ...]]r   r   )
rb   rL   ro   r   r   r  r^   r  r   r   )
rb   rL   ro   r   r   r   r^   r  r   r   r   r   )r   r   r   r   r   r/  rX   r   r5   r%  	dp_stringr1  r   r
   rr   r   r  r]   rV   rT   rS  rS    s   @  N)==	*778	",,-	"**+A  IO
  
 25 9 	
 0 
  
 *-25 : '	
 0 
  482611 :1 1	1
 01 
14 +/

 
 (	

 
 
 

 
rV   rS  c                  ~   ^  \ rS rSr% SrSrSrS\S'   S rS
U 4S jjr	\
      SS j5       r      SS jrS	rU =r$ )GenericFunctionim  a<  Define 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()
        inherit_cache = True


    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"
        inherit_cache = True

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"
        inherit_cache = True

The above function will render as follows:

.. sourcecode:: pycon+sql

    >>> print(func.geo.buffer())
    {printsql}ST_Buffer()

The name will be rendered as is, however without quoting unless the name
contains special characters that require quoting.  To force quoting
on or off for the name, use the :class:`.sqlalchemy.sql.quoted_name`
construct::

    from sqlalchemy.sql import quoted_name


    class GeoBuffer(GenericFunction):
        type = Geometry()
        package = "geo"
        name = quoted_name("ST_Buffer", True)
        identifier = "buffer"
        inherit_cache = True

The above function will render as:

.. sourcecode:: pycon+sql

    >>> print(func.geo.buffer())
    {printsql}"ST_Buffer"()

Type parameters for this class as a
`generic type <https://peps.python.org/pep-0484/#generics>`_ can be passed
and should match the type seen in a :class:`_engine.Result`. For example::

    class as_utc(GenericFunction[datetime.datetime]):
        type = DateTime()
        inherit_cache = True

The above indicates that the following expression returns a ``datetime``
object::

    connection.scalar(select(func.as_utc()))

.. versionadded:: 1.3.13  The :class:`.quoted_name` construct is now
   recognized for quoting when used with the "name" attribute of the
   object, so that quoting can be forced on or off for the function
   name.


Trl   	_registerc                   > [         R                  U R                  ;  a&  U R                  U R                  U R
                  5        [        TU ]  5         g rz   )r   	Annotated__mro___register_generic_functionr   r?  ru   __init_subclass__)clsrw   s    rT   r  !GenericFunction.__init_subclass__  s8    s{{2**3<<F!#rV   c                   UR                  SU5      =U l        nUR                  SU5      =U l        nUR                  SS5      nSU;   a
  US   U l        [	        U SS5      U l        U R
                  (       a  [        X@U5        g SU l        g )Nrb   rP   rR   rN  __return_type__r  T)rR  rb   rP   r   rj   r  rU   )r  clsnameclsdictrb   rP   rR   s         rT   r  *GenericFunction._register_generic_function  s     "++fg664&-kk,&EE++i4'01CH  [$7 ==jw7 !CMrV   c           
        UR                  SS 5      nUc?  U Vs/ s H2  n[        R                  " [        R                  UU R
                  U S9PM4     nnU R                  =(       d    [        U5      U l        SU l        [        [        U[        R                  SS.65      U l        [        R                  " UR                  SS 5      =(       d    [!        U SS 5      5      U l        g s  snf )N_parsed_argsrc   r]   Tre   r   r   )r   r   rh   r   ri   rb   rk   rl   r^   r)   r$   r   rm   rZ   r   r-  rj   r   )rn   rq   rH  parsed_argsrp   s        rT   rr   GenericFunction.__init__  s     jj6  A   //*.	    <4+<#CN++D
 ((JJw%Dvt)D
	%s   9C')rk   rZ   r^   r   )r   r   )r  rL   r  zMapping[str, Any]r   r   )rq   r   rH  r   r   r   )r   r   r   r   r   coerce_argumentsinherit_cacher   rb   r  classmethodr  rr   r  r  r  s   @rT   r  r  m  st    l\ MOD$
 !!$5!	! !(
<
HK
	
 
rV   r  r   r  c                      \ rS rSrSr\R                  " 5       rS rS\	R                  4/rS	S jrS
S jr\SS j5       rSrg)r  i  zRepresent 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.

sequencec                    [        U[        R                  5      (       d   S5       eXl        [        R
                  " UR                  =(       d    [        U SS 5      5      U l        g )Nz0next_value() accepts a Sequence object as input.r   )	r   r   r   r  r   r-  	data_typerj   r   )rn   seqr   s      rT   rr   next_value.__init__.  sX    
 
 	>=	> 
 ((MM8WT648
	rV   c                    [        U[        5      =(       a-    U R                  R                  UR                  R                  :H  $ rz   )r   r  r  rb   )rn   otherr   s      rT   comparenext_value.compare7  s2    uj) :""enn&9&99	
rV   c                    / $ rz   r]   r   s    rT   r   next_value._from_objects=  s    	rV   )r  r   N)r  zschema.Sequencer   r   r   r   )r  r   r   r   r   rl   r   )r   r   r   r   r   r   Integerr   rb   r5   dp_named_ddl_elementr   rr   r  r  r   r  r]   rV   rT   r  r    sS     DD 
&;;<

  rV   r  c                  2    \ rS rSrSrSr      SS jrSrg)AnsiFunctioniB  zEDefine a function in "ansi" format, which doesn't render parenthesis.Tc                8    [         R                  " U /UQ70 UD6  g rz   )r  rr   )rn   rq   rH  s      rT   rr   AnsiFunction.__init__G  s     	  777rV   r]   Nrq   r   rH  r   r   r   )r   r   r   r   r   r	  rr   r  r]   rV   rT   r  r  B  s'    OM838?B8	8rV   r  c                     ^  \ rS rSrSrSr\        S	S j5       r\        S
S j5       r\        SS j5       r      SU 4S jjrSrU =r	$ )ReturnTypeFromArgsiM  zKDefine a function whose return type is bound to the type of its
arguments.
Tc                    g rz   r]   ra  s       rT   rr   ReturnTypeFromArgs.__init__Y       rV   c                    g rz   r]   ra  s       rT   rr   r!  a  r"  rV   c                    g rz   r]   ra  s       rT   rr   r!  i  r"  rV   c           
        > U Vs/ s H2  n[         R                  " [        R                  UU R                  U S9PM4     nnUR                  S[        U5      5        XBS'   [        TU ]   " U0 UD6  g s  snf )Nrc   r   r  )	r   rh   r   ri   rb   
setdefaultr    ru   rr   )rn   rq   rH  rp   fn_argsrw   s        rT   rr   r!  q  s     1
  ++YY&*	  	 1
 	'?7#;<!(~',V,1
s   9A1r]   )r   r  rq   r   rH  r   r   r   )r   r  rq   r   rH  r   r   r   )r   rG   rq   r   rH  r   r   r   )rq   r  rH  r   r   r   )
r   r   r   r   r   r	  r
   rr   r  r  r  s   @rT   r  r  M  s     M  7 	
 
  * 7 	
 
   7 	
 
 -;-GJ-	- -rV   r  c                      \ rS rSrSrSrSrg)ro  i  Tr]   N)r   r   r   r   rk   r	  r  r]   rV   rT   ro  ro    s    IMrV   ro  c                      \ rS rSrSrSrSrg)r  i  z!The SQL MAX() aggregate function.Tr]   Nr   r   r   r   r   r	  r  r]   rV   rT   r  r    
    +MrV   r  c                      \ rS rSrSrSrSrg)r  i  z!The SQL MIN() aggregate function.Tr]   Nr*  r]   rV   rT   r  r    r+  rV   r  c                      \ rS rSrSrSrSrg)r  i  z!The SQL SUM() aggregate function.Tr]   Nr*  r]   rV   rT   r  r    r+  rV   r  c                  >    \ rS rSrSr\R                  " 5       rSrSr	g)r  i  zThe SQL now() datetime function.

SQLAlchemy dialects will usually render this particular function
in a backend-specific way, such as rendering it as ``CURRENT_TIMESTAMP``.

Tr]   N
r   r   r   r   r   r   DateTimer   r	  r  r]   rV   rT   r  r    s     DMrV   r  c                  >    \ rS rSrSr\R                  " 5       rSrSr	g)rv  i  a  The SQL CONCAT() function, which concatenates strings.

E.g.:

.. sourcecode:: pycon+sql

    >>> print(select(func.concat("a", "b")))
    {printsql}SELECT concat(:concat_2, :concat_3) AS concat_1

String concatenation in SQLAlchemy is more commonly available using the
Python ``+`` operator with string datatypes, which will render a
backend-specific concatenation operator, such as :

.. sourcecode:: pycon+sql

    >>> print(select(literal("a") + "b"))
    {printsql}SELECT :param_1 || :param_2 AS anon_1


Tr]   N
r   r   r   r   r   r   Stringr   r	  r  r]   rV   rT   rv  rv    s    * ??DMrV   rv  c                  V   ^  \ rS rSrSr\R                  " 5       rSrSU 4S jjr	Sr
U =r$ )rl  i  zThe CHAR_LENGTH() SQL function.Tc                (   > [         TU ]  " U40 UD6  g rz   ru   rr   )rn   argr   rw   s      rT   rr   char_length.__init__  s     	##rV   r]   )r7  z_ColumnExpressionArgument[str]r   r   r   r   r   r   r   r   r   r   r  r   r	  rr   r  r  r  s   @rT   rl  rl    s#    )DM$ $rV   rl  c                       \ rS rSrSrSrSrSrg)r  i  zThe RANDOM() SQL function.Tr]   Nr   r   r   r   r   rk   r	  r  r]   rV   rT   r  r    s    $IMrV   r  c                  f   ^  \ rS rSrSr\R                  " 5       rSr S     SU 4S jjjr	Sr
U =r$ )rz  i  a  The 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:

.. sourcecode:: sql

    SELECT count(*) AS count_1
    FROM some_table


Tc                D   > Uc  [        S5      n[        TU ]  " U40 UD6  g )N*)r*   ru   rr   )rn   
expressionrH  rw   s      rT   rr   count.__init__  s'     ',J.v.rV   r]   rz   )r?  z7Union[_ColumnExpressionArgument[Any], _StarOrOne, None]rH  r   r   r   r9  r  s   @rT   rz  rz    sJ    . DM 		/
	/
 	/ 
	/ 	/rV   rz  c                  >    \ rS rSrSr\R                  " 5       rSrSr	g)r  i  z The CURRENT_DATE() SQL function.Tr]   N)
r   r   r   r   r   r   Dater   r	  r  r]   rV   rT   r  r        *==?DMrV   r  c                  >    \ rS rSrSr\R                  " 5       rSrSr	g)r  i   z The CURRENT_TIME() SQL function.Tr]   N)
r   r   r   r   r   r   Timer   r	  r  r]   rV   rT   r  r     rC  rV   r  c                  >    \ rS rSrSr\R                  " 5       rSrSr	g)r  i  z%The CURRENT_TIMESTAMP() SQL function.Tr]   Nr/  r]   rV   rT   r  r    s    /DMrV   r  c                  >    \ rS rSrSr\R                  " 5       rSrSr	g)r  i  z The CURRENT_USER() SQL function.Tr]   Nr2  r]   rV   rT   r  r        *??DMrV   r  c                  >    \ rS rSrSr\R                  " 5       rSrSr	g)r  i  zThe localtime() SQL function.Tr]   Nr/  r]   rV   rT   r  r    s    'DMrV   r  c                  >    \ rS rSrSr\R                  " 5       rSrSr	g)r  i  z"The localtimestamp() SQL function.Tr]   Nr/  r]   rV   rT   r  r    s    ,DMrV   r  c                  >    \ rS rSrSr\R                  " 5       rSrSr	g)r  i#  z The SESSION_USER() SQL function.Tr]   Nr2  r]   rV   rT   r  r  #  rH  rV   r  c                  >    \ rS rSrSr\R                  " 5       rSrSr	g)r  i*  zThe SYSDATE() SQL function.Tr]   Nr/  r]   rV   rT   r  r  *  s    %DMrV   r  c                  >    \ rS rSrSr\R                  " 5       rSrSr	g)r  i1  zThe USER() SQL function.Tr]   Nr2  r]   rV   rT   r  r  1  s    "??DMrV   r  c                  @   ^  \ rS rSrSrSr      SU 4S jjrSrU =r$ )rb  i8  ai  Support 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])

.. seealso::

    :func:`_postgresql.array_agg` - PostgreSQL-specific version that
    returns :class:`_postgresql.ARRAY`, which has PG-specific operators
    added.

Tc           	     \  > U Vs/ s H&  n[         R                  " [        R                  X0S9PM(     nnUR	                  S[
        R                  5      nSU;  a9  [        U5      n[        U[
        R                  5      (       a  XbS'   O
U" USS9US'   XBS'   [        TU ](  " U0 UD6  g s  snf )N)rd   _default_array_typer   r   )
dimensionsr  )r   rh   r   ri   r   r   r   r    r   ru   rr   )rn   rq   rH  rp   r'  default_array_typetype_from_argsrw   s          rT   rr   array_agg.__init__L  s     	1
  ++Q 	 	 1
 $ZZ(=x~~N& ,W5N.(..99"0w"4"q#w ")~',V,#1
s   -B)r]   r  )	r   r   r   r   r   r	  rr   r  r  r  s   @rT   rb  rb  8  s1    " M-3-?B-	- -rV   rb  c                  2    \ rS rSrSrSrSr    SS jrSrg)	OrderedSetAggic  zDefine 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.FTc                B   [        [        U R                  R                  5      n[        R
                  " UR                  5      nU R                  (       a<  [        UR                  5      S:  a#  [        R                  " US   R                  5      $ US   R                  $ )Nr   r   )r   r$   rZ   r   sqlutilunwrap_order_byr   array_for_multi_clauserQ  ro   r   r   r   )rn   r   func_clausesr   s       rT   r   OrderedSetAgg.within_group_typek  s{     J(8(8(@(@A181H1H!!2
 &&3|/C/C+Dq+H>>(1+"2"233A;###rV   r]   N)r   zWithinGroup[Any]r   zTypeEngine[Any])	r   r   r   r   r   rZ  r	  r   r  r]   rV   rT   rV  rV  c  s)    5 #M
$,
$	
$rV   rV  c                      \ rS rSrSrSrSrg)r  ix  zImplement 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.

Tr]   Nr*  r]   rV   rT   r  r  x  s     MrV   r  c                       \ rS rSrSrSrSrSrg)r  i  ad  Implement 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.

Tr]   Nr   r   r   r   r   rZ  r	  r  r]   rV   rT   r  r        	 "MrV   r  c                       \ rS rSrSrSrSrSrg)r  i  ad  Implement 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.

Tr]   Nr_  r]   rV   rT   r  r    r`  rV   r  c                  >    \ rS rSrSr\R                  " 5       rSrSr	g)r  i  zImplement 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`.

Tr]   N
r   r   r   r   r   r   r  r   r	  r  r]   rV   rT   r  r         DMrV   r  c                  >    \ rS rSrSr\R                  " 5       rSrSr	g)r  i  zImplement 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`.

Tr]   Nrc  r]   rV   rT   r  r    rd  rV   r  c                  J    \ rS rSr% Sr\R                  " 5       rS\S'   Sr	Sr
g)r  i  zImplement 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`.

!sqltypes.Numeric[decimal.Decimal]r   Tr]   Nr   r   r   r   r   r   Numericr   r   r	  r  r]   rV   rT   r  r    "     /7.>.>.@D
+@MrV   r  c                  J    \ rS rSr% Sr\R                  " 5       rS\S'   Sr	Sr
g)r  i  zImplement 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`.

rg  r   Tr]   Nrh  r]   rV   rT   r  r    rj  rV   r  c                       \ rS rSrSrSrSrSrg)r}  i  a7  Implement the ``CUBE`` grouping operation.

This function is used as part of the GROUP BY of a statement,
e.g. :meth:`_expression.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

Tr]   Nr;  r]   rV   rT   r}  r}         IMrV   r}  c                       \ rS rSrSrSrSrSrg)r  i  a;  Implement the ``ROLLUP`` grouping operation.

This function is used as part of the GROUP BY of a statement,
e.g. :meth:`_expression.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

Tr]   Nr;  r]   rV   rT   r  r    rm  rV   r  c                       \ rS rSrSrSrSrSrg)r  i  a  Implement the ``GROUPING SETS`` grouping operation.

This function is used as part of the GROUP BY of a statement,
e.g. :meth:`_expression.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

Tr]   Nr;  r]   rV   rT   r  r    s    4 IMrV   r  c                  f   ^  \ rS rSrSr\R                  " 5       rSrSr	      SU 4S jjr
SrU =r$ )rZ  i   a  Implement a generic string aggregation function.

This function will concatenate non-null values into a string and
separate the values by a delimiter.

This function is compiled on a per-backend basis, into functions
such as ``group_concat()``, ``string_agg()``, or ``LISTAGG()``.

e.g. Example usage with delimiter '.'::

    stmt = select(func.aggregate_strings(table.c.str_col, "."))

The return type of this function is :class:`.String`.

.. versionadded: 2.0.21

Tc                $   > [         TU ]  X5        g rz   r6  )rn   clause	separatorrw   s      rT   rr   aggregate_strings.__init__7  s     	+rV   r]   )rr  r   rs  rL   r   r   )r   r   r   r   r   r   r3  r   rk   r	  rr   r  r  r  s   @rT   rZ  rZ     sB    $ ??DIM,4,AD,	, ,rV   rZ  )rN  )rP   rL   rQ   zType[Function[Any]]rR   rL   r   r   )r   
__future__r   datetimedecimaltypingr   r   r   r   r   r	   r
   r   r   r   r   r   r    r   r   r   r   r   r   r   r   rX  _typingr   baser   r   r   r   r   elementsr    r!   r"   r#   r$   r%   r&   r(   r)   r*   r+   r-   r/   
selectabler0   r1   r2   r3   r4   visitorsr5   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   engine.baserB   engine.cursorrC   engine.interfacesrD   rE   util.typingrF   rG   rI   defaultdictdictrJ   r   rU   rX   r   r   r5  rX  modifierrS  r  r   r  r  r  ro  r  r  r  r  rL   rv  rl  floatr  rz  dater  timer  r  r  r  r  r  r  r  rb  rV  r  r  r  r  r  Decimalr  r  r}  r  r  rZ  r]   rV   rT   <module>r     sZ   ; "                         ( # "    % & #    #  $  $ !  ! "  ( $   '  $2;<#,&',+'(,;?"TT 	T 
@  >H,7:	0I
3j-"3Z I
3X1', 1h0;r? 04\* \*B !))E*w
r" w
ti
hrl i
X &$  )W %"% "J8?2& 82-, 2-j!"% 

R
  
R
  
R
  	/(++
, 	_S! 4	$/#& 	$_U# $/OC  $/N<. <. X%6%67 <$ X../ \("3"34 <$ l8,,- < (-"8B<0 (-V$OB' $*
= 
mB'  mB'  ?3 % ?7??3 0 ?2 $_R  $OB' >,, ,rV   