
    ؄_                         d dl mZ ddlmZ ddlmZ ddlmZ ddlmZ  G d dej                  Z	 G d	 d
e          Z
d ZdS )   )ARRAY   )elements)
expression)	functions)ColumnCollectionConstraintc                   T    e Zd ZdZd Zd ZddZd Zej	        fdZ
ed             ZdS )	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`

    c                    t          j        |          | _        t          |          }|dk    rt	          d          |dk    r!t          j        |d                   | _        d S t          j        |dt           j        i| _        d S )N    z)at least one ORDER BY element is requiredr   _literal_as_text)r   _literal_as_bindstargetlen	TypeErrororder_by
ClauseList)selfr   r   _lobs       g/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/ext.py__init__zaggregate_order_by.__init__4   s    0888}}199GHHHQYY$6x{CCDMMM$/,4,F DMMM    Nc                     | S N )r   againsts     r   
self_groupzaggregate_order_by.self_groupA   s    r   c                     | j         | j        fS r   r   r   )r   kwargss     r   get_childrenzaggregate_order_by.get_childrenD   s    {DM))r   c                 R     || j         fi || _          || j        fi || _        d S r   r   )r   clonekws      r   _copy_internalsz"aggregate_order_by._copy_internalsG   s<    eDK..2..dm22r22r   c                 4    | j         j        | j        j        z   S r   )r   _from_objectsr   )r   s    r   r'   z aggregate_order_by._from_objectsK   s    {(4=+FFFr   r   )__name__
__module____qualname____doc____visit_name__r   r   r!   r   _cloner%   propertyr'   r   r   r   r
   r
      s           D *N     * * * %-O 3 3 3 3 G G XG G Gr   r
   c                   V    e Zd ZdZdZdZ ej        ddd          d             Zd Z	dS )	ExcludeConstraintzA table-level EXCLUDE constraint.

    Defines an EXCLUDE constraint as described in the `postgres
    documentation`__.

    __ http://www.postgresql.org/docs/9.0/static/sql-createtable.html#SQL-CREATETABLE-EXCLUDE

    exclude_constraintNwherez:class:`.ExcludeConstraint`z$:paramref:`.ExcludeConstraint.where`c                    g }g }i | _         t          | \  }}t          |                     |          |          D ]d\  \  }}}	}
}|
|                    |
           ||j        n|	}|
|| j         |<   t          j        |          }|                    |||f           e|| _        t          j	        | g|R |
                    d          |
                    d          |
                    d          d |
                    dd          | _        |
                    d          }|t          j        |d	
          | _        dS dS )a  
        Create an :class:`.ExcludeConstraint` object.

        E.g.::

            const = ExcludeConstraint(
                (Column('period'), '&&'),
                (Column('group'), '='),
                where=(Column('group') != 'some group')
            )

        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'
                )
            )

        :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.

        Nname
deferrable	initially)r4   r5   r6   usinggistr2   T)allow_coercion_to_text)	operatorszip"_extract_col_expression_collectionappendr4   r   _literal_as_column_render_exprsr   r   getr7   r   r2   )r   r   r$   columnsrender_exprsexpressionsr:   exprcolumnstrnameadd_elementoperatorr4   r2   s                 r   r   zExcludeConstraint.__init__^   s   P !$hY>A33K@@)?
 ?
 	8 	8:0T67K( &{+++"("46;;'D'/t$066DtX 67777)"+	
	
 	
 vvl++ff[))	
 	
 	
 	
 VVGV,,
w#4d  DJJJ r   c           	            fd j                                         D             }  j        | j         j         j         j         j        d}|j        	                     j                   |S )Nc                 .    g | ]}|j         |         fS r   )r:   ).0colr   s     r   
<listcomp>z*ExcludeConstraint.copy.<locals>.<listcomp>   s%    NNN3S$.-.NNNr   )r4   r5   r6   r2   r7   )
rA   keys	__class__r4   r5   r6   r2   r7   dispatch_update)r   r$   r   cs   `   r   copyzExcludeConstraint.copy   s}    NNNN$,:K:K:M:MNNNDNn**
 
 
 	

4=)))r   )
r(   r)   r*   r+   r,   r2   r   _document_text_coercionr   rS   r   r   r   r0   r0   P   sq          *NE%X%%. 
g g 
gR    r   r0   c                  B    t           |d<   t          j        j        | 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.

    .. versionadded:: 1.1

    _default_array_type)r   r   func	array_agg)argr$   s     r   rX   rX      s'     !&B>#S/B///r   N)arrayr   sqlr   r   r   
sql.schemar   ColumnElementr
   r0   rX   r   r   r   <module>r^      s                            4 4 4 4 4 4>G >G >G >G >G1 >G >G >GBG G G G G2 G G GT
0 
0 
0 
0 
0r   