g?ddlmZddlmZddlmZddlmZddlmZddlm Z dd l m Z dd l m Z dd l m Z dd l mZdd l mZddl mZddlmZddlmZddlmZedeZerddlmZGdde j2ZGddeZdZGddej:eZGddeZGddeZ Gd d!eZ!Gd"d#eZ"Gd$d%eZ#Gd&d'eZ$y())) annotations)Any) TYPE_CHECKING)TypeVar)types)ARRAY) coercions)elements) expression) functions)roles)schema)ColumnCollectionConstraint)TEXT)InternalTraversal_T)bound)_TraverseInternalsTypeceZdZUdZdZdZdejfdejfdejfgZ de d<dZ dd Z d Z ejfd Zed Zy )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_internalscvtjtj||_|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) r expectrExpressionElementRolerrlen TypeErrorrr ClauseList)selfrr_lobs S/opt/hc_python/lib64/python3.12/site-packages/sqlalchemy/dialects/postgresql/ext.py__init__zaggregate_order_by.__init__Ns&&u'B'BFK KK$$ 8} 19GH H QY%,,++Xa[DM%//161L1LDMNc|SN)r%againsts r' self_groupzaggregate_order_by.self_group^s r)c 2|j|jfSr+rr)r%kwargss r' get_childrenzaggregate_order_by.get_childrenas{{DMM))r)c d||jfi||_||jfi||_yr+r0)r%clonekws r'_copy_internalsz"aggregate_order_by._copy_internalsds,DKK.2. dmm2r2 r)c\|jj|jjzSr+)r _from_objectsr)r%s r'r8z aggregate_order_by._from_objectshs!{{((4==+F+FFFr)r+)__name__ __module__ __qualname____doc____visit_name__stringify_dialectrdp_clauseelementdp_typer__annotations__r(r.r2r _cloner6propertyr8r,r)r'rr s"H*N$ $556 "**+ &7783/  *%-OO3GGr)rcneZdZdZdZdZdZdZejdddd 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_constraintNFrwherez: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)rIrJrKusinggistrGops) operatorszipr expect_col_expression_collectionrDDLConstraintColumnRoleappendrI _render_exprsrr(getrLr StatementOptionRolerGrN)r%r r5columns render_exprs expressionsrOexprcolumnstrname add_elementoperatorrIrGs r'r(zExcludeConstraint.__init__~sL~ !$h Y>A  6 6--{   ? : 0T67K( &{+"("46;;'D'/t$   tX 6 7? "*"++   vvl+ff[)  VVGV, w  "))%*C*CUKDJ66%$r)c t|||jDcgc]*\}}}t|ts|n|j |||f,c}}}|_ycc}}}wr+)super _set_parentrT isinstancestrc)r%tabler5rZrIr^ __class__s r'razExcludeConstraint._set_parentsf E"*.););  *<$dH 'tS1uwwt}  *<   s/Ac r|jDcgc])\}}}tj||j||f+}}}}|j||j |j |j|j|jd}|jj|j|Scc}}}w)N)rIrJrKrGrL) rTr_copy_expressionparentrfrIrJrKrGrLdispatch_update)r% target_tabler5rZ_r^r rds r'_copyzExcludeConstraint._copys &*%7%7  &8!a''dkk<H &8   DNN nn****   4==)! s.B2r+)r9r:r;r<r=rG inherit_cachecreate_drop_stringify_dialectr _document_text_coercionr(rarn __classcell__rfs@r'rErEmsT*N EM$0!%X%%%. %  %B  r)rEcRt|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)argr5s r'rwrw$s)!&B >> # #S /B //r)c"eZdZdZfdZxZS) _regconfig_fnTc t|}t|dkDrTtjtj |j dt|dd|tj}|g}ng}|Dcgc]4}tjtj |t|dd|6}}t|,||zi|ycc}w)NrrrI)rIapply_propagate_attrstype_rIr|) listr"r r rr!popgetattrr REGCONFIGr`r()r%argsr1 initial_argrd addtl_argsrfs r'r(z_regconfig_fn.__init__2sDz t9q=#**++ T640&*oo K'-KK    ++T640&*      ;3?? s59C)r9r:r;ror(rrrss@r'rzrz/sM@@r)rzc,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)r9r:r;r<rorTSVECTORrr,r)r'rrLs"M >>Dr)rc,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 TNr9r:r;r<rorTSQUERYrr,r)r'rrb"M ==Dr)rc,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,r)r'rrxrr)rc,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,r)r'rrrr)rc,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,r)r'rrrr)rc*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) NFrTrrI)r|rIr}r~)rr"rbr ColumnElementr_type_affinityrrr r rr!rrrr`r()r%rr1 has_regconfigrrdrrfs r'r(zts_headline.__init__s Dz t9q=!M tAw 6 6 7Q ++u}}<"M M #**++ &*T640oo K'-KK    ++T640&*      ;3?? s9D) r9r:r;r<rorrr(rrrss@r'rrs "M D&@&@r)rN)% __future__rtypingrrrrarrayr sqlr r r rrr sql.schemar sql.sqltypesr sql.visitorsrrrrrrErwGenericFunctionrzrrrrrrr,r)r'rs# 4 - T6JG11JGZt2tn0@I--b1@:-,,m,},=,;@-;@r)