
    -h!                         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\R                  5      r " S S\5      rS rg)   )ARRAY   )util)	coercions)elements)
expression)	functions)roles)schema)ColumnCollectionConstraint)InternalTraversalc                       \ rS rSrSrS rSrS\R                  4S\R                  4S\R                  4/r
S rSS	 jrS
 r\R                  4S jr\S 5       rSrg)aggregate_order_by   a  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`


postgresqltargettypeorder_byc                    [         R                  " [        R                  U5      U l        U R                  R
                  U l        [        U5      nUS:X  a  [        S5      eUS:X  a.  [         R                  " [        R                  US   5      U l        g [        R                  " US[        R                  06U l        g )N    z)at least one ORDER BY element is requiredr   _literal_as_text_role)r   expectr
   ExpressionElementRoler   r   len	TypeErrorr   r   
ClauseList)selfr   r   _lobs       wC:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\sqlalchemy/dialects/postgresql/ext.py__init__aggregate_order_by.__init__@   s    &&u'B'BFKKK$$	8}19GHHQY%,,++Xa[DM %//161L1LDM    Nc                     U $ N )r   againsts     r   
self_groupaggregate_order_by.self_groupP   s    r"   c                 2    U R                   U R                  4$ r$   r   r   )r   kwargss     r   get_childrenaggregate_order_by.get_childrenS   s    {{DMM))r"   c                 d    U" U R                   40 UD6U l         U" U R                  40 UD6U l        g r$   r*   )r   clonekws      r   _copy_internals"aggregate_order_by._copy_internalsV   s,    DKK.2.dmm2r2r"   c                 \    U R                   R                  U R                  R                  -   $ r$   )r   _from_objectsr   )r   s    r   r4    aggregate_order_by._from_objectsZ   s!    {{((4==+F+FFFr"   )r   r   r   r$   )__name__
__module____qualname____firstlineno____doc____visit_name__stringify_dialectr   dp_clauseelementdp_type_traverse_internalsr    r'   r,   r   _cloner1   propertyr4   __static_attributes__r%   r"   r   r   r      s}     D *N$	$556	"**+	&778 * %-OO 3 G Gr"   r   c                   z   ^  \ rS rSrSrSrSrSrSr\	R                  " SSS	5      S
 5       rU 4S jrSS jrSrU =r$ )ExcludeConstraint_   zA 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`c                    / n/ n0 U l         [        U6 u  pV[        [        R                  " [        R
                  U5      U5       HR  u  u  pxpnU
b  UR                  U
5        Ub  UR                  OU	nUb  XR                   U'   UR                  X|U45        MT     X@l        [        R                  " U /UQ7UR                  S5      UR                  S5      UR                  S5      S.6  UR                  SS5      U l        UR                  S5      nUb*  [        R                  " [        R                  U5      U l        UR                  S	0 5      U l        g)
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'}
        )
    )

: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 <value> when issuing DDL
  for this constraint.

:param using:
  Optional string.  If set, emit USING <index_method> when issuing DDL
  for this constraint. Defaults to 'gist'.

:param where:
  Optional SQL expression construct or literal SQL string.
  If set, emit WHERE <predicate> 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 <postgresql_operator_classes>`
  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)rI   rJ   rK   usinggistrG   ops)	operatorszipr    expect_col_expression_collectionr
   DDLConstraintColumnRoleappendrI   _render_exprsr   r    getrL   r   StatementOptionRolerG   rN   )r   r   r0   columnsrender_exprsexpressionsrO   exprcolumnstrnameadd_elementoperatorrI   rG   s                 r   r    ExcludeConstraint.__init__p   s@   n !$h>A66--{ 	?
:0T7( &{+"("46;;'D'/t$X 67?
" *"++	
	
 vvl+ff[)	
 VVGV,
w"))%*C*CUKDJ66%$r"   c           
        > [         [        U ]  U5        [        R                  " U R
                  U R                  5       VVVVs/ s H.  u  u  p4pV[        U[        R                  5      (       a  UOUUU4PM0     snnnnU l        g s  snnnnf r$   )
superrD   _set_parentr   zip_longestrT   rW   
isinstancer   ClauseElement)r   tabler0   rZ   rI   r^   colexpr	__class__s          r   rb   ExcludeConstraint._set_parent   s    259 483C3C""DLL4	
4/&X	 #4)?)?@@g
4	
 	
s   5B
c           	         U R                    Vs/ s H=  n[        R                  " X0R                  U5      U R                  UR
                     4PM?     nnU R                  " UU R
                  U R                  U R                  U R                  U R                  S.6nUR                  R                  U R                  5        U$ s  snf )N)rI   rJ   rK   rG   rL   )rW   r   _copy_expressionparentrO   rI   rh   rJ   rK   rG   rL   dispatch_update)r   target_tabler0   rZ   r   cs         r   _copyExcludeConstraint._copy   s     

 % ''kk<Htyy) % 	 
 NNnn****
 	


4==)!
s   AC)rT   rO   rN   rL   rG   r$   )r6   r7   r8   r9   r:   r;   rG   inherit_cachecreate_drop_stringify_dialectr   _document_text_coercionr    rb   rq   rB   __classcell__)rh   s   @r   rD   rD   _   sW     *NEM$0!%%%.
w%
w%r
 r"   rD   c                  T    [         US'   [        R                  R                  " U 0 UD6$ )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.

.. versionadded:: 1.1

_default_array_type)r   r	   func	array_agg)argr0   s     r   rz   rz     s)     !&B>>##S/B//r"   N)arrayr    r   sqlr   r   r   r	   r
   r   
sql.schemar   sql.visitorsr   ColumnElementr   rD   rz   r%   r"   r   <module>r      sQ            4 -HG11 HGVn2 nb
0r"   