L iCTddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z d d l m Z d d l m Z d d lmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZer*d dlmZd dlmZd dlmZd dl m!Z!d dl"m#Z#d dlm$Z$d dlm%Z%e deZ&Gdd ej>e&Z'Gd!d"eZ(d#Z)Gd$d%ejTe&Z+Gd&d'e+Z,Gd(d)e+Z-Gd*d+e+Z.Gd,d-e+Z/Gd.d/e+Z0Gd0d1e+Z1y2)3) annotations)Any)Iterable)List)Optional)overload) TYPE_CHECKING)TypeVar)types)ARRAY) coercions)elements) expression) functions)roles)schema)ColumnCollectionConstraint)TEXT)InternalTraversal)_ColumnExpressionArgument) ClauseElement) ColumnElement) OperatorType) FromClause)_CloneCallableType)_TraverseInternalsType_T)boundceZdZUdZdZdZdejfdejfdejfgZ de d<e ddZ e dd Z dd Z d dd Z dd Zej f ddZeddZy )aggregate_order_byaRepresent a PostgreSQL aggregate order by expression. E.g.:: from sqlalchemy.dialects.postgresql import aggregate_order_by expr = func.array_agg(aggregate_order_by(table.c.a, table.c.b.desc())) stmt = select(expr) would represent the expression: .. sourcecode:: sql SELECT array_agg(a ORDER BY b DESC) FROM table; Similarly:: expr = func.string_agg( table.c.a, aggregate_order_by(literal_column("','"), table.c.a) ) stmt = select(expr) Would represent: .. sourcecode:: sql SELECT string_agg(a, ',' ORDER BY a) FROM table; .. versionchanged:: 1.2.13 - the ORDER BY argument may be multiple terms .. seealso:: :class:`_functions.array_agg` postgresqltargettypeorder_byr_traverse_internalscyNselfr$r&s h/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/dialects/postgresql/ext.py__init__zaggregate_order_by.__init__X  cyr)r*r+s r-r.zaggregate_order_by.__init___r/r0cztjtj||_|jj |_t |}||dk(r td|dk(r-tjtj|d|_ytj|dtji|_y)Nrz)at least one ORDER BY element is requiredr _literal_as_text_role) rexpectrExpressionElementRoler$r%len TypeErrorr&r ClauseList)r,r$r&_lobs r-r.zaggregate_order_by.__init__fs &/%5%5  ' '&  KK$$ 8} 19GH H QY%,,++Xa[DM%//161L1LDMr0Nc|Sr)r*)r,againsts r- self_groupzaggregate_order_by.self_group}s  r0c 2|j|jfSr)r$r&)r,kwargss r- get_childrenzaggregate_order_by.get_childrens{{DMM))r0c d||jfi||_||jfi||_yr)r>)r,clonekws r-_copy_internalsz"aggregate_order_by._copy_internalss.DKK.2. dmm2r2 r0c\|jj|jjzSr))r$ _from_objectsr&)r,s r-rFz aggregate_order_by._from_objectss!{{((4==+F+FFFr0)r$zColumnElement[_T]r&_ColumnExpressionArgument[Any])r$z_ColumnExpressionArgument[_T]r&rGr))r;zOptional[OperatorType]returnr)r?rrHzIterable[ClauseElement])rBrrCrrHNone)rHzList[FromClause])__name__ __module__ __qualname____doc____visit_name__stringify_dialectrdp_clauseelementdp_typer'__annotations__rr.r<r@r_clonerDpropertyrFr*r0r-r"r"*s"H*N$ $556 "**+ &7783/  ! 2   - 2  -2015-  *+3//3'3AD3 3 GGr0r"cneZdZdZdZdZdZdZejdddd Z fd Z d d Z xZ S) ExcludeConstraintzA table-level EXCLUDE constraint. Defines an EXCLUDE constraint as described in the `PostgreSQL documentation`__. __ https://www.postgresql.org/docs/current/static/sql-createtable.html#SQL-CREATETABLE-EXCLUDE exclude_constraintNFr#wherez:class:`.ExcludeConstraint`z$:paramref:`.ExcludeConstraint.where`cg}g}i|_t|\}}ttjtj ||D]R\\}}} } } | |j | | |jn| } | | |j| <|j || | fT||_tj|g||jd|jd|jdd|jdd|_ |jd} | )tjtj| |_|jd i|_y) a Create an :class:`.ExcludeConstraint` object. E.g.:: const = ExcludeConstraint( (Column("period"), "&&"), (Column("group"), "="), where=(Column("group") != "some group"), ops={"group": "my_operator_class"}, ) The constraint is normally embedded into the :class:`_schema.Table` construct directly, or added later using :meth:`.append_constraint`:: some_table = Table( "some_table", metadata, Column("id", Integer, primary_key=True), Column("period", TSRANGE()), Column("group", String), ) some_table.append_constraint( ExcludeConstraint( (some_table.c.period, "&&"), (some_table.c.group, "="), where=some_table.c.group != "some group", name="some_table_excl_const", ops={"group": "my_operator_class"}, ) ) The exclude constraint defined in this example requires the ``btree_gist`` extension, that can be created using the command ``CREATE EXTENSION btree_gist;``. :param \*elements: A sequence of two tuples of the form ``(column, operator)`` where "column" is either a :class:`_schema.Column` object, or a SQL expression element (e.g. ``func.int8range(table.from, table.to)``) or the name of a column as string, and "operator" is a string containing the operator to use (e.g. `"&&"` or `"="`). In order to specify a column name when a :class:`_schema.Column` object is not available, while ensuring that any necessary quoting rules take effect, an ad-hoc :class:`_schema.Column` or :func:`_expression.column` object should be used. The ``column`` may also be a string SQL expression when passed as :func:`_expression.literal_column` or :func:`_expression.text` :param name: Optional, the in-database name of this constraint. :param deferrable: Optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when issuing DDL for this constraint. :param initially: Optional string. If set, emit INITIALLY when issuing DDL for this constraint. :param using: Optional string. If set, emit USING when issuing DDL for this constraint. Defaults to 'gist'. :param where: Optional SQL expression construct or literal SQL string. If set, emit WHERE when issuing DDL for this constraint. :param ops: Optional dictionary. Used to define operator classes for the elements; works the same way as that of the :ref:`postgresql_ops ` parameter specified to the :class:`_schema.Index` construct. .. versionadded:: 1.3.21 .. seealso:: :ref:`postgresql_operator_classes` - general description of how PostgreSQL operator classes are specified. Nname deferrable initially)rZr[r\usinggistrXops) operatorszipr expect_col_expression_collectionrDDLConstraintColumnRoleappendrZ _render_exprsrr.getr]r4StatementOptionRolerXr_)r,rrCcolumns render_exprs expressionsr`exprcolumnstrname add_elementoperatorrZrXs r-r.zExcludeConstraint.__init__sQ~ !$h Y>A  6 6--{   ?  8 : 0T67K( &{+"("46;;'D'/t$   tX 6 7 8"*"++   vvl+ff[)  VVGV, w  "))%*C*CUKDJ66%$r0c t|||jDcgc]*\}}}t|ts|n|j |||f,c}}}|_ycc}}}wr))super _set_parentre isinstancestrc)r,tablerCrkrZro __class__s r-rrzExcludeConstraint._set_parent'sc E"*.););   %dH 'tS1uwwt}   s/Ac r|jDcgc])\}}}tj||j||f+}}}}|j||j |j |j|j|jd}|jj|j|Scc}}}w)N)rZr[r\rXr]) rer_copy_expressionparentrwrZr[r\rXr]dispatch_update)r, target_tablerCrk_rorrus r-_copyzExcludeConstraint._copy3s &*%7%7   "a''dkk<H    DNN nn****   4==)! s.B2r))rJrKrLrMrNrX inherit_cachecreate_drop_stringify_dialectr_document_text_coercionr.rrr __classcell__rws@r-rVrVsT*N EM$0!%X%%%. %  %B  r0rVcRt|d<tjj|i|S)zPostgreSQL-specific form of :class:`_functions.array_agg`, ensures return type is :class:`_postgresql.ARRAY` and not the plain :class:`_types.ARRAY`, unless an explicit ``type_`` is passed. _default_array_type)r rfunc array_agg)argrCs r-rrGs)!&B >> # #S /B //r0c"eZdZdZfdZxZS) _regconfig_fnTc t|}t|dkDrTtjtj |j dt|dd|tj}|g}ng}|Dcgc]4}tjtj |t|dd|6}}t|,||zi|ycc}w)Nr rrZ)rZapply_propagate_attrstype_rZr) listr6rr4rr5popgetattrr REGCONFIGrqr.)r,argsr? initial_argru addtl_argsrws r-r.z_regconfig_fn.__init__UsDz t9q=#**++ T640&*oo K'-KK    ++T640&*     ;3?? s59C)rJrKrLrr.rrs@r-rrRsM@@r0rc,eZdZdZdZej Zy) to_tsvectoraThe PostgreSQL ``to_tsvector`` SQL function. This function applies automatic casting of the REGCONFIG argument to use the :class:`_postgresql.REGCONFIG` datatype automatically, and applies a return type of :class:`_postgresql.TSVECTOR`. Assuming the PostgreSQL dialect has been imported, either by invoking ``from sqlalchemy.dialects import postgresql``, or by creating a PostgreSQL engine using ``create_engine("postgresql...")``, :class:`_postgresql.to_tsvector` will be used automatically when invoking ``sqlalchemy.func.to_tsvector()``, ensuring the correct argument and return type handlers are used at compile and execution time. .. versionadded:: 2.0.0rc1 TN)rJrKrLrMrr TSVECTORr%r*r0r-rros"M >>Dr0rc,eZdZdZdZej Zy) to_tsqueryaThe PostgreSQL ``to_tsquery`` SQL function. This function applies automatic casting of the REGCONFIG argument to use the :class:`_postgresql.REGCONFIG` datatype automatically, and applies a return type of :class:`_postgresql.TSQUERY`. Assuming the PostgreSQL dialect has been imported, either by invoking ``from sqlalchemy.dialects import postgresql``, or by creating a PostgreSQL engine using ``create_engine("postgresql...")``, :class:`_postgresql.to_tsquery` will be used automatically when invoking ``sqlalchemy.func.to_tsquery()``, ensuring the correct argument and return type handlers are used at compile and execution time. .. versionadded:: 2.0.0rc1 TNrJrKrLrMrr TSQUERYr%r*r0r-rr"M ==Dr0rc,eZdZdZdZej Zy)plainto_tsqueryaThe PostgreSQL ``plainto_tsquery`` SQL function. This function applies automatic casting of the REGCONFIG argument to use the :class:`_postgresql.REGCONFIG` datatype automatically, and applies a return type of :class:`_postgresql.TSQUERY`. Assuming the PostgreSQL dialect has been imported, either by invoking ``from sqlalchemy.dialects import postgresql``, or by creating a PostgreSQL engine using ``create_engine("postgresql...")``, :class:`_postgresql.plainto_tsquery` will be used automatically when invoking ``sqlalchemy.func.plainto_tsquery()``, ensuring the correct argument and return type handlers are used at compile and execution time. .. versionadded:: 2.0.0rc1 TNrr*r0r-rrrr0rc,eZdZdZdZej Zy)phraseto_tsqueryaThe PostgreSQL ``phraseto_tsquery`` SQL function. This function applies automatic casting of the REGCONFIG argument to use the :class:`_postgresql.REGCONFIG` datatype automatically, and applies a return type of :class:`_postgresql.TSQUERY`. Assuming the PostgreSQL dialect has been imported, either by invoking ``from sqlalchemy.dialects import postgresql``, or by creating a PostgreSQL engine using ``create_engine("postgresql...")``, :class:`_postgresql.phraseto_tsquery` will be used automatically when invoking ``sqlalchemy.func.phraseto_tsquery()``, ensuring the correct argument and return type handlers are used at compile and execution time. .. versionadded:: 2.0.0rc1 TNrr*r0r-rrrr0rc,eZdZdZdZej Zy)websearch_to_tsqueryaThe PostgreSQL ``websearch_to_tsquery`` SQL function. This function applies automatic casting of the REGCONFIG argument to use the :class:`_postgresql.REGCONFIG` datatype automatically, and applies a return type of :class:`_postgresql.TSQUERY`. Assuming the PostgreSQL dialect has been imported, either by invoking ``from sqlalchemy.dialects import postgresql``, or by creating a PostgreSQL engine using ``create_engine("postgresql...")``, :class:`_postgresql.websearch_to_tsquery` will be used automatically when invoking ``sqlalchemy.func.websearch_to_tsquery()``, ensuring the correct argument and return type handlers are used at compile and execution time. .. versionadded:: 2.0.0rc1 TNrr*r0r-rrrr0rc*eZdZdZdZeZfdZxZS) ts_headlineaThe PostgreSQL ``ts_headline`` SQL function. This function applies automatic casting of the REGCONFIG argument to use the :class:`_postgresql.REGCONFIG` datatype automatically, and applies a return type of :class:`_types.TEXT`. Assuming the PostgreSQL dialect has been imported, either by invoking ``from sqlalchemy.dialects import postgresql``, or by creating a PostgreSQL engine using ``create_engine("postgresql...")``, :class:`_postgresql.ts_headline` will be used automatically when invoking ``sqlalchemy.func.ts_headline()``, ensuring the correct argument and return type handlers are used at compile and execution time. .. versionadded:: 2.0.0rc1 Tc 0t|}t|dkrd}nKt|dtjr,|dj j tjurd}nd}|rTtjtj|jd|t|ddtj}|g}ng}|Dcgc]4}tjtj|t|dd|6}}t!|D||zi|ycc}w) NFr TrrZ)rrZrr)rr6rsrrr%_type_affinityr rrr4rr5rrrrqr.)r,rr? has_regconfigrrurrws r-r.zts_headline.__init__sDz t9q=!M tAw 6 6 7Q ++u}}<"M M #**++ &*T640oo K'-KK    ++T640&*     ;3?? s9D) rJrKrLrMrrr%r.rrs@r-rrs "M D&@&@r0rN)2 __future__rtypingrrrrrr r r arrayr sqlrrrrrr sql.schemar sql.sqltypesr sql.visitorsr sql._typingr sql.elementsrr sql.operatorsrsql.selectablerrrrr"rVrGenericFunctionrrrrrrrr*r0r-rs# 4 -8---,26 TcG11"5cGLt2tn0@I--b1@:-,,m,},=,;@-;@r0