U ÂÏ aÒ!ã@sšddlmZddlmZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd l m Z Gd d „d ej ƒZGd d„de ƒZdd„ZdS)é)ÚARRAYé)Úutil)Ú coercions)Úelements)Ú expression)Ú functions)Úroles)Úschema)ÚColumnCollectionConstraintc@sLeZdZdZdZdZdd„Zddd„Zdd „Ze j fd d „Z e d d „ƒZ dS)Úaggregate_order_byaûRepresent 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:: 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:: SELECT string_agg(a, ',' ORDER BY a) FROM table; .. versionadded:: 1.1 .. versionchanged:: 1.2.13 - the ORDER BY argument may be multiple terms .. seealso:: :class:`_functions.array_agg` Ú postgresqlcGsjt tj|¡|_|jj|_t|ƒ}|dkr4tdƒ‚n2|dkrRt tj|d¡|_nt j |dtjiŽ|_dS)Néz)at least one ORDER BY element is requiredrZ_literal_as_text_role) rÚexpectr ZExpressionElementRoleÚtargetÚtypeÚlenÚ TypeErrorÚorder_byrZ ClauseList)ÚselfrrZ_lob©rúcC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-nyjtotrf\sqlalchemy\dialects\postgresql\ext.pyÚ__init__:s  ÿÿÿzaggregate_order_by.__init__NcCs|S©Nr)rZagainstrrrÚ self_groupJszaggregate_order_by.self_groupcKs |j|jfSr©rr)rÚkwargsrrrÚ get_childrenMszaggregate_order_by.get_childrencKs$||jf|Ž|_||jf|Ž|_dSrr)rÚcloneÚkwrrrÚ_copy_internalsPsz"aggregate_order_by._copy_internalscCs|jj|jjSr)rÚ _from_objectsr)rrrrr!Tsz aggregate_order_by._from_objects)N)Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú__visit_name__Zstringify_dialectrrrrZ_cloner Úpropertyr!rrrrr s" r csLeZdZdZdZdZdZe ddd¡dd „ƒZ ‡fd d „Z dd d „Z ‡Z S)ÚExcludeConstraintzàA table-level EXCLUDE constraint. Defines an EXCLUDE constraint as described in the `PostgreSQL documentation`__. __ https://www.postgresql.org/docs/9.0/static/sql-createtable.html#SQL-CREATETABLE-EXCLUDE Zexclude_constraintNr Úwherez:class:`.ExcludeConstraint`z$:paramref:`.ExcludeConstraint.where`cOsúg}g}i|_t|Ž\}}tt tj|¡|ƒD]V\\}}} } } | dk rP| | ¡|dk r^|jn| } | dk rt| |j| <| || | f¡q.||_t j |f|ž|  d¡|  d¡|  d¡dœŽ|  dd¡|_ |  d¡} | dk rèt  tj| ¡|_|  d i¡|_dS) a2 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'} ) ) :param \*elements: A sequence of two tuples of the form ``(column, operator)`` where "column" is a SQL expression element or a raw SQL string, most typically a :class:`_schema.Column` object, and "operator" is a string containing the operator to use. 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. :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. NÚnameÚ deferrableÚ initially)r*r+r,ÚusingZgistr)Úops)Ú operatorsÚziprZ expect_col_expression_collectionr ZDDLConstraintColumnRoleÚappendr*Ú _render_exprsr rÚgetr-rZStatementOptionRoler)r.)rrrÚcolumnsZ render_exprsZ expressionsr/ÚexprÚcolumnZstrnameZ add_elementÚoperatorr*r)rrrris@W ÿü  ÿþû zExcludeConstraint.__init__c s0tt|ƒ |¡dd„t |j|j¡Dƒ|_dS)NcSs0g|](\\}}}}t|tjƒr"|n|||f‘qSr)Ú isinstancerZ ClauseElement)Ú.0r5r*r7ZcolexprrrrÚ ês  üýz1ExcludeConstraint._set_parent..)Úsuperr(Ú _set_parentrÚ zip_longestr2r4)rÚtabler©Ú __class__rrr<çsÿúzExcludeConstraint._set_parentc sJ‡‡fdd„ˆjDƒ}ˆj|ˆjˆjˆjˆjˆjdœŽ}|j ˆj¡|S)Ncs(g|] }t |ˆjˆ¡ˆj|jf‘qSr)r Z_copy_expressionÚparentr/r*)r9r5©rÚ target_tablerrr:ösý þz+ExcludeConstraint._copy..)r*r+r,r)r-) r4r@r*r+r,r)r-ÚdispatchÚ_update)rrCrrÚcrrBrÚ_copyõs ûúzExcludeConstraint._copy)N) r"r#r$r%r&r)Zcreate_drop_stringify_dialectrZ_document_text_coercionrr<rGÚ __classcell__rrr?rr(Ys ý y r(cOst|d<tjj||ŽS)zêPostgreSQL-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. .. versionadded:: 1.1 Z_default_array_type)rrÚfuncÚ array_agg)ÚargrrrrrJ s rJN)ÚarrayrÚrZsqlrrrrr r Z sql.schemar Z ColumnElementr r(rJrrrrÚs         F1