L if UdZddlmZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$dd l%m&Z&dd!l%m'Z'dd"l%m(Z(dd#l%m)Z)dd$l%m*Z*dd%l%m+Z+dd&l%m,Z,dd'l%m-Z-dd(l%m.Z.dd)l%m/Z/dd*l%m0Z0dd+l%m1Z1dd,l%m2Z2dd-l3m4Z4dd.l3m5Z5dd/l3m6Z6dd0lm7Z7dd1lm8Z8dd2l9m:Z:d3dlmZer`dd4lm;Z;dd5lmZ>dd8lm?Z?dd9lm@Z@dd:lmAZAdd;l%mBZBddlmEZEd3d?lFmGZGd3d@lHmIZId3dAlJmKZKd3dBlJmLZLd3dClMmNZNedDeEZOedFeEZPejeRZSdGeTdH< d ddIZUGdJdKe"e+eOe4e#ZVGdLdMe'eZWGdNdOe0eOZXGdPdQZYeYZZeYjeZ_eYdRSZ[GdTdUeVeOZ\GdVdWe\eOZ]eUdXe)eUdYe,GdZd[e]e^Z_Gd\d]e]eOZ`Gd^d_e]eOZaGd`daeaeOZbGdbdceaeOZcGdddeeaeOZdGdfdgeaeOZeGdhdie]ejZfGdjdke]egZhGdldme]e^ZiGdndoe]ejZkGdpdqe]e^ZlGdrdse`ejZnGdtdue`ejZpGdvdwe`ejZqGdxdye`egZrGdzd{e`ejZsGd|d}e`ejZtGd~de`egZuGdde`ejZvGdde`egZwGddeae eOZxGdde]eOZyGddeyeOZzGddeyeOZ{GddeyeOZ|Gdde]e^Z}Gdde]e^Z~Gdde]ejZGdde]ejZGdde]eOZGdde]eOZGdde]eOZGdde]egZy)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)ExtractFunctionFilter)Grouping)literal_column) NamedColumnOver 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]]]] _registryct|}t|j}||vr$tjdj ||||<y)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)rJstrlowerrwarnformat) identifierfnpackageregs ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/sql/functions.pyregister_functionrUZsP G CZ&&(JS  ))/ ); C OceZdZUdZdej fdej fdejfgejzZ dZ de d<dZ dZd Zd e d<d e d <d e d <de d< d(dZd Zed)fd Z d*dZ d+ d,dZ d-dZ d. d/dZej2d0dZej6d0dZed1dZe d0dZej@d2dZ!d d d d d d d3dZ" d4dZ#e$d5dZ%e$ d6dZ% d7dZ% d8d Z&ed)d!Z' d9d"Z( d. d:d#Z)d;d$Z* d. dd'Z-xZ.S)?FunctionElementaBase for SQL function-oriented constructs. This is a `generic type `_, 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_typezTuple[str, ...] packagenamesFNzOptional[TableValueType]r primary_key _is_clone_ofz Grouping[Any]c |Dcgc]4}tjtj|t |dd|6}}|j xs t ||_tt|tjdd|_ ycc}w)aOConstruct 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` nameNraapply_propagate_attrsToperatorgroup_contents) rexpectrExpressionElementRolegetattr _has_argsboolr)r$rcomma_oprY)selfclausescargss rT__init__zFunctionElement.__init__s2:    ++T640&*  : : 54:# $ 2 24 O : s9Bc6t|xs t|ddS)Nra)super _proxy_keyri)rm __class__s rTrtzFunctionElement._proxy_keysw!@WT64%@@rVc(|j|||SN)_execute_function)rm connectiondistilled_paramsexecution_optionss rT_execute_on_connectionz&FunctionElement._execute_on_connections ++ "$5  rVct|||S)aReturn 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)rmratype_s rTscalar_table_valuedz#FunctionElement.scalar_table_valuedsB$D$66rVc|j}|jdd}|jdd}|jdd}|r ||fz }d|_t|x|_|_|j ||S)a 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_ordinalityNjoins_implicitlyraTrar) _generatepoprZr3typer[alias)rmexprkwnew_funcrrras rT table_valuedzFunctionElement.table_valuedsV>>#&&!2D966"4d;vvfd#  _& &D(,H %5CT5JJ 2~~4:J~KKrVc<|j||jS)aQReturn 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)rcolumnrmrars rT column_valuedzFunctionElement.column_valuedGsRzzt6FzGNNNrVc|jS)aThe 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. )rorms rTcolumnszFunctionElement.columnsrs 0vv rVclt|jDcgc]}|j|fc}Scc}w)z-synonym for :attr:`.FunctionElement.columns`.r)r_all_selected_columnskey)rmcols rTrozFunctionElement.cs0 /3/I/IJcggs^J  Js1ct|jr"td|jj}|S|j dg}|S)N!Sequence[KeyedColumnElement[Any]])rrr _elementslabel)rmcolss rTrz%FunctionElement._all_selected_columnssF tyy )3TYY5H5HD  JJt$%D rVc|jSrwrrs rTexported_columnsz FunctionElement.exported_columnss||rVcJtt|jjS)z}Return the underlying :class:`.ClauseList` which contains the arguments for this :class:`.FunctionElement`. )rr$rYelementrs rTrnzFunctionElement.clausess J 0 0 8 899rV partition_byorder_byrowsrange_groupsc$t||||||S)aBProduce 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` rr,)rmrrrrrs rToverzFunctionElement.overs$B %   rVct|g|S)aProduce 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.)rmrs rT within_groupzFunctionElement.within_groups$4+(++rVcyrwr\rs rTfilterzFunctionElement.filters!rVcyrwr\)rm_FunctionElement__criterion0 criterions rTrzFunctionElement.filters !rVc"|s|St|g|S)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')rmrs rTrzFunctionElement.filters:Kd/Y//rVct|||S)as 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)rm left_index right_indexs rT as_comparisonzFunctionElement.as_comparisonsV j+>>rVc.|jjSrw)rn _from_objectsrs rTrzFunctionElement._from_objectsds||)))rVcy)aFor 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\)rmrs rTwithin_group_typez!FunctionElement.within_group_typehsrVcHtj|||j|S)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 `` 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` )ratable_value_typer)r2 _constructrrs rTrzFunctionElement.aliasvs(R ** !YY-   rVclt|}|jr|jdi|j}|S)zProduce a :func:`_expression.select` construct against this :class:`.FunctionElement`. This is shorthand for:: s = select(function_element) r\)r1_execution_optionsr{)rmss rTselectzFunctionElement.selects6   " "###>d&=&=>ArVc <td|f||jd||d|S)NT)_compared_to_operator_compared_to_typeuniquer expanding)r"rrmreobjrrrs rT _bind_paramzFunctionElement._bind_params;    #+"ii    rVc~|tjtjfvr t|St||S)N)against)rgetitemjson_getitem_opr)rs self_group)rmrrus rTrzFunctionElement.self_groups; y(()*C*CD DD> !7%g%6 6rVc,t|jS)zzoverrides FromClause.entity_namespace as functions are generally column expressions and not FromClauses. )rrYrs rTentity_namespacez FunctionElement.entity_namespaces!!1!122rV)rn'_ColumnExpressionOrLiteralArgument[Any]returnNonerr)ryrBrzrDr{rErzCursorResult[Any]rw)rarLr!Optional[_TypeEngineArgument[_T]]rzScalarFunctionColumn[_T])rz(_ColumnExpressionOrStrLabelArgument[Any]rrrr2NF)ra Optional[str]rrkrzTableValuedColumn[_T])rz.ColumnCollection[str, KeyedColumnElement[Any]])rr)rr$) rOptional[_ByArgument]rrr-Optional[Tuple[Optional[int], Optional[int]]]rrrrrzOver[_T])r_ColumnExpressionArgument[Any]rzWithinGroup[_T])rrF)r_ColumnExpressionArgument[bool]rrrzFunctionFilter[_T])rrrzUnion[Self, FunctionFilter[_T]])rintrrrr)rzWithinGroup[_S]rzOptional[TypeEngine[_S]])rarrrkrr2)rzSelect[Tuple[_T]] rerArrrzOptional[TypeEngine[_T]]rrkrrrzBindParameter[_T])rzOptional[OperatorType]rr>)rr=)/__name__ __module__ __qualname____doc__r5dp_clauseelement dp_booleandp_has_cache_keyr_executable_traverse_internals_traverse_internalsr]__annotations__rjrZr[rq_non_anon_labelpropertyrtr|rrrrro_non_memoized_propertyrro_memoized_propertyrorrrmemoized_attributernrrr rrrrrrrrr __classcell__rus@rTrXrXrsi, )::; .99: /@@A 11 2 %'L/&I26/6 ?  @O AA  2 7    EI!7!7 A!7 !!7FWL=WLEHWL WLtDI)O!)O<@)O )OV ""#2      7 ##:$:/3*.>B@D@D( ,( ( ( < ( > ( >(  ( T,7, ,(!! !5!4!  !! 090 (0BK?K?,/K? K?Z** +  ! DIN !N <@N N ` $+/    (        &733rVrXc6eZdZUdejfdej fdej fdej fgZded<ded<ded<ddZ ddZ e dd Z e jdd Z e dd Zejdd Zese ZeZy y )r sql_functionrr modifiersFunctionElement[Any]rc0tj|||Srw)r%_gen_cache_key)rmanon_map bindparamss rTrzFunctionAsBinary._gen_cache_keys++D(JGGrVc||_||_||_tj|_t j|_d|_ d|_ tji|_ y)NT)rrrrfunction_as_comparison_oprer BOOLEANTYPErnegate_is_implicitly_booleanr immutabledictr)rmrQrrs rTrqzFunctionAsBinary.__init__ sV$&!;; ((  &*#++B/rVcb|jjj|jdz SNrrrnrrs rT left_exprzFunctionAsBinary.left_exprs(  ((0011DEErVcd||jjj|jdz <yrrrmvalues rTrzFunctionAsBinary.left_exprs'AF!!))$//A*=>rVcb|jjj|jdz Srrrnrrs rT right_exprzFunctionAsBinary.right_expr s*  ((001A1AA1EFFrVcd||jjj|jdz <yrrrs rTrzFunctionAsBinary.right_expr$s)BG!!))$*:*:Q*>?rVN)rrrrrr)rQrrrrrrr)rColumnElement[Any])rrrr)rrrr5r dp_plain_obj dp_plain_dictrrrrqrrsetterrrleftrightr\rVrTrrs *;;< (556 )667 '556 '&OH 0& 047 0FI 0  0FFGGGGHH  rVrceZdZdZdej fdej fdejfgZdZ dZ d d dZ y) r~scalar_function_columnrarrQFNcT||_||_tj||_yrw)rQrar to_instancer)rmrQrars rTrqzScalarFunctionColumn.__init__<s&  ((/ rVrw)rQzFunctionElement[_T]rarLrrrr) rrr__visit_name__r5 dp_anon_namedp_typerr is_literaltablerqr\rVrTr~r~0sz-N "//0 "**+  112 J E 48 0  0 01 0  0rVr~ceZdZdZd:dZd;dZe ddZ e d?dZ e d@d Z e dAd Z e dBd Z dCd Z e dDd Z e dEdZe dFdZe dGdZe dHdZ dIdZe dJdZe dKdZe dLdZe dMdZe dNdZe dOdZe dPdZe dQdZe dRdZe dSdZe dTdZe dUdZe dVdZe dWd Ze dXd!Ze dYd"Z dZd#Ze d[d$Ze d\d%Ze d]d&Z d^d'Ze d_d(Ze d`d)Z e dad*Z!e dbd+Z"e dcd,Z#e ddd-Z$e ded.Z%e dfd/Z&e dgd0Z'e dhd1Z(e did2Z)e djd3Z*e dkd4Z*e dld5Z* dmd6Z*e dnd7Z+e dod8Z,y9y9)p_FunctionGeneratora 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  g|_||_yrw)_FunctionGenerator__namesopts)rmrs rTrqz_FunctionGenerator.__init__s"$  rVc |jdr |j|S|j dr|dd}t di|j }t|j|gz|_|S#t$r t|wxYw)N___rr\) startswith__dict__KeyErrorAttributeErrorendswithrrlistr)rmrafs rT __getattr__z_FunctionGenerator.__getattr__s ??4  +}}T**]]3 ":D  + +&$/  +$T** +s A--Bcyrwr\)rmrrokwargss rT__call__z_FunctionGenerator.__call__srVcyrwr\)rmror)s rTr*z_FunctionGenerator.__call__ADrVc |jj}|j|t|j}|dk(r|j\}}n|dk(rd|jd}}nd}|0t |j j}|||i|St|jdg|dt|jddi|S)Nr6r_defaultrrr]) rcopyupdatelenrrJgetrMFunctiontuple)rmror)otokensrRfnamefuncs rTr*z_FunctionGenerator.__call__s IINN  T\\" Q;!\\NGU q['aUGG  W%))%++-8DQ}!}$ LL  GH +0a1C+D LM  rVcyrwr\rs rTaggregate_stringsz$_FunctionGenerator.aggregate_strings@CrVcyrwr\rs rT ansifunctionz_FunctionGenerator.ansifunctions;>rVcyrwr\rmrrpr)s rT array_aggz_FunctionGenerator.array_agg  rVcyrwr\r?s rTr@z_FunctionGenerator.array_aggrArVcyrwr\r?s rTr@z_FunctionGenerator.array_aggrArVcyrwr\r?s rTr@z_FunctionGenerator.array_aggs  rVcyrwr\rs rTrz_FunctionGenerator.cast+.rVcyrwr\rs rT char_lengthz_FunctionGenerator.char_lengths47rVcyrwr\r?s rTcoalescez_FunctionGenerator.coalesce rVcyrwr\r?s rTrJz_FunctionGenerator.coalescerKrVcyrwr\r?s rTrJz_FunctionGenerator.coalescerKrVcyrwr\r?s rTrJz_FunctionGenerator.coalesce's rVcyrwr\rs rTconcatz_FunctionGenerator.concat.*-rVcyrwr\rs rTcountz_FunctionGenerator.count1s(+rVcyrwr\rs rTcubez_FunctionGenerator.cube4rFrVcyrwr\rs rT cume_distz_FunctionGenerator.cume_dist703rVcyrwr\rs rT current_datez_FunctionGenerator.current_date:69rVcyrwr\rs rT current_timez_FunctionGenerator.current_time=r[rVcyrwr\rs rTcurrent_timestampz$_FunctionGenerator.current_timestamp@r;rVcyrwr\rs rT current_userz_FunctionGenerator.current_userCr[rVcyrwr\rs rT dense_rankz_FunctionGenerator.dense_rankF25rVcyrwr\rs rTextractz_FunctionGenerator.extractI,/rVcyrwr\rs rT grouping_setsz _FunctionGenerator.grouping_setsL=@rVcyrwr\rs rT localtimez_FunctionGenerator.localtimeOrXrVcyrwr\rs rTlocaltimestampz!_FunctionGenerator.localtimestampRs:=rVcyrwr\r?s rTmaxz_FunctionGenerator.maxZ rVcyrwr\r?s rTrpz_FunctionGenerator.maxbrqrVcyrwr\r?s rTrpz_FunctionGenerator.maxjrqrVcyrwr\r?s rTrpz_FunctionGenerator.maxr rVcyrwr\r?s rTminz_FunctionGenerator.min~rqrVcyrwr\r?s rTrwz_FunctionGenerator.minrqrVcyrwr\r?s rTrwz_FunctionGenerator.minrqrVcyrwr\r?s rTrwz_FunctionGenerator.minrurVcyrwr\rs rTmodez_FunctionGenerator.moderFrVcyrwr\rs rT next_valuez_FunctionGenerator.next_valuerdrVcyrwr\rs rTnowz_FunctionGenerator.nows$'rVcyrwr\rs rT orderedsetaggz _FunctionGenerator.orderedsetaggrjrVcyrwr\rs rT percent_rankz_FunctionGenerator.percent_rankr[rVcyrwr\rs rTpercentile_contz"_FunctionGenerator.percentile_contr,rVcyrwr\rs rTpercentile_discz"_FunctionGenerator.percentile_discr,rVcyrwr\rs rTrandomz_FunctionGenerator.randomrQrVcyrwr\rs rTrankz_FunctionGenerator.rank&)rVcyrwr\rs rTrollupz_FunctionGenerator.rollups/2rVcyrwr\rs rT session_userz_FunctionGenerator.session_userr[rVcyrwr\r?s rTsumz_FunctionGenerator.sumrqrVcyrwr\r?s rTrz_FunctionGenerator.sumrqrVcyrwr\r?s rTrz_FunctionGenerator.sumrqrVcyrwr\r?s rTrz_FunctionGenerator.sumrurVcyrwr\rs rTsysdatez_FunctionGenerator.sysdatergrVcyrwr\rs rTuserz_FunctionGenerator.userrrVN)rrrr)rarLrr)rorr_TypeEngineArgument[_T]r)rrz Function[_T])rorr)rrz Function[Any])rzType[aggregate_strings])rzType[AnsiFunction[Any]])rColumnElement[_T]rprr)rr array_agg[_T])r_ColumnExpressionArgument[_T]rprr)rrr)rrGrprr)rrr)r&_ColumnExpressionOrLiteralArgument[_T]rprr)rrr)rzType[Cast[Any]])rzType[char_length])rrrprr)rr coalesce[_T])rrrprr)rrr)rrGrprr)rrr)rrrprr)rrr)rz Type[concat])rz Type[count])rzType[cube[Any]])rzType[cume_dist])rzType[current_date])rzType[current_time])rzType[current_timestamp])rzType[current_user])rzType[dense_rank])rz Type[Extract])rzType[grouping_sets[Any]])rzType[localtime])rzType[localtimestamp])rrrprr)rrmax[_T])rrrprr)rrr)rrGrprr)rrr)rrrprr)rrr)rrrprr)rrmin[_T])rrrprr)rrr)rrGrprr)rrr)rrrprr)rrr)rzType[mode[Any]])rzType[next_value])rz Type[now])rzType[OrderedSetAgg[Any]])rzType[percent_rank])rzType[percentile_cont[Any]])rzType[percentile_disc[Any]])rz Type[random])rz Type[rank])rzType[rollup[Any]])rzType[session_user])rrrprr)rrsum[_T])rrrprr)rrr)rrGrprr)rrr)rrrprr)rrr)rz Type[sysdate])rz Type[user])-rrrrrqr'r r*rrr:r=r@rrHrJrPrSrUrWrZr]r_rarcrfrirlrnrprwr|r~rrrrrrrrrrrrr\rVrTrrJsRWr 5AD DD , 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 ;       / / ) )erVrF)groupc@eZdZUdZdZej dejfdejfdejfgzZde d<de d<de d< e d d d  dd Z e d d d  dd Z d d d  ddZ d ddZy )r3aDescribe 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]rarrLrPzTypeEngine[_T].)rr]cyrwr\rmrarr]rns rTrqzFunction.__init__/rVcyrwr\rs rTrqzFunction.__init__8rrVNc|xsd|_||_tj||_t j |g|y)zConstruct a :class:`.Function`. The :data:`.func` construct is normally used to construct new :class:`.Function` instances. r\N)r]rarrrrXrqrs rTrqzFunction.__init__As?).B ((/   00rVc Pt|j|f||j|d|d|S)NT)rrrrr)r"rarrs rTrzFunction._bind_paramWs? II   #+"ii    rV) rarLrnrrrr]Optional[Tuple[str, ...]]rr) rarLrnrrrr]rrr) rarLrnrrrr]rrrrr)rrrrrrXrr5r  dp_stringrrr rqrr\rVrTr3r3s@ N)== *778 ",,- "**+A IO   25 9  0    *-25 :'  0   4826 11:11 1 0 1  14+/    (        rVr3cneZdZUdZdZdZded<dZdfd Ze d dZ d dZ xZ S) GenericFunctionatDefine 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 `_ 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. Trk _registerctj|jvr&|j|j|j t |yrw)r Annotated__mro___register_generic_functionrr!rs__init_subclass__)clsrus rTrz!GenericFunction.__init_subclass__s8   s{{ 2  * *3<< F !#rVc|jd|x|_}|jd|x|_}|jdd}d|vr |d|_t |dd|_|j rt |||yd|_y)NrarPrRr.__return_type__rT)r2rarPrrirrU)rclsnameclsdictrarPrRs rTrz*GenericFunction._register_generic_functions"++fg664&-kk,&EE++i4  '01CH [$7  == j#w 7!CMrVc |jdd}|>|Dcgc]3}tjtj||j |5}}|j xs t||_d|_tt|tjdd|_ tj|jddxs t!|dd|_ycc}w)N _parsed_argsrbr\Trdrr)rrrgrrhrarjrkr]r)r$rrlrYrrrir)rmrpr) parsed_argsros rTrqzGenericFunction.__init__sjj6     //*. K<4 +<# CN++D   (( JJw % Dvt)D  %s8C)rr)rrLrzMapping[str, Any]rr)rprr)rrr) rrrrcoerce_arguments inherit_cacherrar classmethodrrqrrs@rTrrksol\MO D$ !!$5! !!( < HK  rVrrrfcveZdZdZej ZdZdejfgZ ddZ ddZ e d dZy) r~aRepresent 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 t|tjsJd||_t j |j xs t|dd|_y)Nz0next_value() accepts a Sequence object as input.r) isinstancerr rrr data_typerir)rmseqrs rTrqznext_value.__init__,sU   > = >  (( MM 8WT648  rVc t|txr-|jj|jjk(Srw)rr~rra)rmotherrs rTcompareznext_value.compare5s2 uj ) : ""enn&9&99 rVcgSrwr\rs rTrznext_value._from_objects;s rVN)rzschema.Sequencerrrr)rrrrrrkr)rrrrrIntegerrrar5dp_named_ddl_elementrrqrrrr\rVrTr~r~sU 8   D D &;;<  rVr~c(eZdZdZdZ ddZy) AnsiFunctionzEDefine a function in "ansi" format, which doesn't render parenthesis.Tc6tj|g|i|yrw)rrq)rmrpr)s rTrqzAnsiFunction.__init__Es   777rVNrprr)rrr)rrrrrrqr\rVrTrr@s'OM838?B8 8rVrceZdZdZdZe ddZe ddZe d dZ d fd ZxZS) ReturnTypeFromArgszSDefine a function whose return type is bound to the type of its arguments. Tcyrwr\r?s rTrqzReturnTypeFromArgs.__init__W rVcyrwr\r?s rTrqzReturnTypeFromArgs.__init___rrVcyrwr\r?s rTrqzReturnTypeFromArgs.__init__grrVc |Dcgc]3}tjtj||j|5}}|j dt |||d<t| |i|ycc}w)Nrbrr) rrgrrhra setdefaultr rsrq)rmrpr)rofn_argsrus rTrqzReturnTypeFromArgs.__init__os}1    ++YY&*  1 1  '?7#;>> 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 TNrrrrrStringrrr\rVrTrPrPs* 8?? DMrVrPcJeZdZdZej ZdZdfd ZxZ S)rHzThe CHAR_LENGTH() SQL function.Tc &t||fi|yrwrsrq)rmargrrus rTrqzchar_length.__init__s ##rV)rz_ColumnExpressionArgument[str]rrrr rrrrrrrrrqrrs@rTrHrHs%) 8   DM$$rVrHceZdZdZdZdZy)rzThe RANDOM() SQL function.TNrrrrrjrr\rVrTrrs$IMrVrcXeZdZdZej ZdZ d dfd ZxZ S)rSaThe 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 @| td}t||fi|y)N*)r*rsrq)rm expressionr)rus rTrqzcount.__init__s'  ',J .v.rVrw)rz7Union[_ColumnExpressionArgument[Any], _StarOrOne, None]r)rrrrrs@rTrSrSsL. 8   DM  /  /  /  / /rVrSc6eZdZdZej ZdZy)rZz The CURRENT_DATE() SQL function.TN)rrrrrDaterrr\rVrTrZrZ* 8==?DMrVrZc6eZdZdZej ZdZy)r]z The CURRENT_TIME() SQL function.TN)rrrrrTimerrr\rVrTr]r]rrVr]c6eZdZdZej ZdZy)r_z%The CURRENT_TIMESTAMP() SQL function.TNrr\rVrTr_r_s/ 8   DMrVr_c6eZdZdZej ZdZy)raz The CURRENT_USER() SQL function.TNrr\rVrTrara * 8?? DMrVrac6eZdZdZej ZdZy)rlzThe localtime() SQL function.TNrr\rVrTrlrls' 8   DMrVrlc6eZdZdZej ZdZy)rnz"The localtimestamp() SQL function.TNrr\rVrTrnrns, 8   DMrVrnc6eZdZdZej ZdZy)rz The SESSION_USER() SQL function.TNrr\rVrTrr!rrVrc6eZdZdZej ZdZy)rzThe SYSDATE() SQL function.TNrr\rVrTrr(s% 8   DMrVrc6eZdZdZej ZdZy)rzThe USER() SQL function.TNrr\rVrTrr/s" 8?? DMrVrc4eZdZdZdZ dfd ZxZS)r@aSupport 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. TcV|Dcgc](}tjtj||*}}|j dt j }d|vr8t|}t|t j r||d<n ||d|d<||d<t|(|i|ycc}w)N)rc_default_array_typerr) dimensionsr) rrgrrhrrARRAYr rrsrq)rmrpr)rordefault_array_typetype_from_argsrus rTrqzarray_agg.__init__Js 1    ++Qd 1 1 $ZZ(=x~~N & ,W5N.(..9"0w"4"q#w")~ ',V,#1 s-B&r)rrrrrrqrrs@rTr@r@6s1"M-3-?B- --rVr@c(eZdZdZdZdZ ddZy) OrderedSetAggzDefine 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.FTc2tt|jj}t j |j }|jr:t|jdkDr"tj|djS|djS)Nrr) rr$rYrsqlutilunwrap_order_byrarray_for_multi_clauser1rnrrr)rmr func_clausesrs rTrzOrderedSetAgg.within_group_typeis{J(8(8(@(@A 181H1H  ! !2   & &3|/C/C+Dq+H>>(1+"2"23 3A;## #rVN)rzWithinGroup[Any]rzTypeEngine[Any])rrrrr rrr\rVrTrras)5#M $, $  $rVrceZdZdZdZy)r|aImplement 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. TNrr\rVrTr|r|vsMrVr|ceZdZdZdZdZy)ra|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. TNrrrrr rr\rVrTrr "MrVrceZdZdZdZdZy)ra|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. TNrr\rVrTrrrrVrc6eZdZdZej ZdZy)raImplement 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`. TNrrrrrrrrr\rVrTrr 8   DMrVrc6eZdZdZej ZdZy)rca 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`. TNrr\rVrTrcrcrrVrccBeZdZUdZej Zded<dZy)raImplement 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]rTN rrrrrNumericrrrr\rVrTrr$/?h.>.>.@D +@MrVrcBeZdZUdZej Zded<dZy)rWa 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`. rrTNrr\rVrTrWrWrrVrWceZdZdZdZdZy)rUaSImplement 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 TNrr\rVrTrUrU IMrVrUceZdZdZdZdZy)raWImplement 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 TNrr\rVrTrrrrVrceZdZdZdZdZy)riaImplement 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 TNrr\rVrTriris4IMrVricZeZdZdZej ZdZdZ dfd Z xZ S)r:aImplement 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|||yrwr)rmclause separatorrus rTrqzaggregate_strings.__init__5s +rV)r"rr#rLrr) rrrrrrrrjrrqrrs@rTr:r:sD$ 8?? DIM,4,AD, ,,rVr:)r.)rPrLrQzType[Function[Any]]rRrLrr)r __future__rdatetimedecimaltypingrrrrrr r r r r rrrrrrrrrrrr _typingrbaserrrrrelementsr r!r"r#r$r%r&r(r)r*r+r-r/ selectabler0r1r2r3r4visitorsr5r7r8r9r:r;r<r=r>r?r@rA engine.baserB engine.cursorrCengine.interfacesrDrE util.typingrFrGrI defaultdictdictrJrrUrXrr~rr8modifierr3rrr~rrrJrprwrrrLrPrHfloatrrSdaterZtimer]r_rarlrnrrrr@rr|rrrrcDecimalrrWrUrrir:r\rVrTr9s\;" (#"%&# #$$!!"($ '$2;<#,&',+'(,;?" T TDT @ >H,7: 0G 3j-"3ZG 3T1',1h0;r?04\*\*B !)) E *w r"w ti hrli X&$)W%"%"J8?2&82-,2-j!"%  R   R   R  /(++ , _S !4 $/#& $_U #$/OC $/N< .< . X%6%67<$ X../\("3"34<$l8,,-< (-"8B<0(-V$OB'$* =   mB'  mB'  ?3   %  ?7??3  0 ?2 $_R $OB'>,,,rV