
    *'&hC                       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 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 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 ddlmZ ddlmZ ddlmZ ddlmZ er*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# ddlm$Z$ ddlm%Z%  e	de          Z& G d d ej        e&                   Z' G d! d"e          Z(d# Z) G d$ d%ej*        e&                   Z+ G d& d'e+          Z, G d( d)e+          Z- G d* d+e+          Z. G d, d-e+          Z/ G d. d/e+          Z0 G d0 d1e+          Z1d2S )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)boundc                      e Zd ZU dZd ZdZdej        fdej        fdej        fgZ	de
d<   edd
            Zed d            Zd dZ	 d!d"dZd#dZej        fd$dZed%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:

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

    
postgresqltargettypeorder_byr   _traverse_internalsColumnElement[_T]_ColumnExpressionArgument[Any]c                    d S N selfr$   r&   s      ]/var/www/html/reinick/venv/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/ext.py__init__zaggregate_order_by.__init__X   	    
 s    _ColumnExpressionArgument[_T]c                    d S r+   r,   r-   s      r/   r0   zaggregate_order_by.__init___   r1   r2   c                `   t          j        t          j        |          | _        | j        j        | _        t          |          }|  |dk    rt          d          |dk    r,t          j        t          j        |d                   | _        d S t          j
        |dt          j        i| _        d S )Nr   z)at least one ORDER BY element is requiredr   _literal_as_text_role)r   expectr   ExpressionElementRoler$   r%   len	TypeErrorr&   r   
ClauseList)r.   r$   r&   _lobs       r/   r0   zaggregate_order_by.__init__f   s    
 &/%5'&
 &
 K$	8}}$199GHHHQYY%,+Xa[ DMMM %/161L DMMMr2   NagainstOptional[OperatorType]returnr   c                    | S r+   r,   )r.   r=   s     r/   
self_groupzaggregate_order_by.self_group}   s	     r2   kwargsr   Iterable[ClauseElement]c                    | j         | j        fS r+   r$   r&   )r.   rB   s     r/   get_childrenzaggregate_order_by.get_children   s    {DM))r2   cloner   kwNonec                R     || j         fi || _          || j        fi || _        d S r+   rE   )r.   rG   rH   s      r/   _copy_internalsz"aggregate_order_by._copy_internals   s>     eDK..2..dm22r22r2   List[FromClause]c                4    | j         j        | j        j        z   S r+   )r$   _from_objectsr&   )r.   s    r/   rN   z aggregate_order_by._from_objects   s    {(4=+FFFr2   )r$   r(   r&   r)   )r$   r3   r&   r)   r+   )r=   r>   r?   r   )rB   r   r?   rC   )rG   r   rH   r   r?   rI   )r?   rL   )__name__
__module____qualname____doc____visit_name__stringify_dialectr   dp_clauseelementdp_typer'   __annotations__r   r0   rA   rF   r   _clonerK   propertyrN   r,   r2   r/   r"   r"   *   s:        " "H *N$	$56	"*+	&783        X    X   0 15    
* * * * +3/3 3 3 3 3 G G G XG G Gr2   r"   c                  p     e Zd ZdZdZdZdZdZ ej	        ddd          d	             Z
 fd
ZddZ xZ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`c                   g }g }i | _         t          | \  }}t          t          j        t          j        |          |          D ]P\  \  }}}	}
}|
|                    |
           ||j        n|	}|
|| j         |<   |                    |||f           Q|| _        t          j
        | g|R |                    d          |                    d          |                    d          d |                    dd          | _        |                    d          }|$t          j        t          j        |          | _        |                    d	i           | _        dS )
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 <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)r_   r`   ra   usinggistr]   ops)	operatorszipr    expect_col_expression_collectionr   DDLConstraintColumnRoleappendr_   _render_exprsr   r0   getrb   r7   StatementOptionRoler]   rd   )r.   r   rH   columnsrender_exprsexpressionsre   exprcolumnstrnameadd_elementoperatorr_   r]   s                 r/   r0   zExcludeConstraint.__init__   s   ~ !$hY>A6-{  	?
 ?
 	8 	8:0T67K( &{+++"("46;;'D'/t$tX 67777)"+	
	
 	
 vvl++ff[))	
 	
 	
 	
 VVGV,,
w")%*CUKKDJ66%$$r2   c                |    t                                                     fd| j        D             | _        d S )Nc                f    g | ]-\  }}}t          |t                    s|nj        |         ||f.S r,   )
isinstancestrc).0rp   r_   rt   tables       r/   
<listcomp>z1ExcludeConstraint._set_parent.<locals>.<listcomp>*  sU     
 
 
 %dH	 'tS11Duwt}
 
 
r2   )super_set_parentrj   )r.   r{   rH   	__class__s    ` r/   r~   zExcludeConstraint._set_parent'  sR    E"""
 
 
 
 *.);
 
 
r2   c           	           fd j         D             }  j        | j         j         j         j         j        d}|j                             j                   |S )Nc                R    g | ]#\  }}}t          j        |j                  |f$S r,   )r   _copy_expressionparent)rz   rp   _rt   r.   target_tables       r/   r|   z+ExcludeConstraint._copy.<locals>.<listcomp>4  sJ     
 
 

 "a 'dk<HH
 
 
r2   )r_   r`   ra   r]   rb   )	rj   r   r_   r`   ra   r]   rb   dispatch_update)r.   r   rH   r   ry   s   ``   r/   _copyzExcludeConstraint._copy3  s    
 
 
 
 

 &*%7
 
 
 DNn**
 
 
 	

4=)))r2   r+   )rO   rP   rQ   rR   rS   r]   inherit_cachecreate_drop_stringify_dialectr   _document_text_coercionr0   r~   r   __classcell__r   s   @r/   r[   r[      s          *NEM$0!%X%%. 
% % 
%B

 

 

 

 

       r2   r[   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.

    _default_array_type)r   r   func	array_agg)argrH   s     r/   r   r   G  s'     !&B>#S/B///r2   c                  "     e Zd ZdZ fdZ xZS )_regconfig_fnTc           	     L    t          |          }t          |          dk    rSt          j        t          j        |                    d          t           dd            t          j	                  }|g}ng } fd|D             } t                      j        ||z   i | d S )Nr   r   r_   )r_   apply_propagate_attrstype_c                r    g | ]3}t          j        t          j        |t	          d d                    4S r_   N)r_   r   r   r7   r   r8   getattrrz   ry   r.   s     r/   r|   z*_regconfig_fn.__init__.<locals>.<listcomp>c  X     
 
 
  +T6400&*	  
 
 
r2   )listr9   r   r7   r   r8   popr   r   	REGCONFIGr}   r0   )r.   argsrB   initial_arg
addtl_argsr   s   `    r/   r0   z_regconfig_fn.__init__U  s    Dzzt99q==#*+T6400&*o  K '-KKK
 
 
 
 
 
 

 	;3??????r2   )rO   rP   rQ   r   r0   r   r   s   @r/   r   r   R  sF        M@ @ @ @ @ @ @ @ @r2   r   c                  $    e Zd ZdZdZej        ZdS )to_tsvectora  The 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)rO   rP   rQ   rR   r   r   TSVECTORr%   r,   r2   r/   r   r   o  s&         " M>DDDr2   r   c                  $    e Zd ZdZdZej        ZdS )
to_tsquerya  The 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

    TNrO   rP   rQ   rR   r   r   TSQUERYr%   r,   r2   r/   r   r     &         " M=DDDr2   r   c                  $    e Zd ZdZdZej        ZdS )plainto_tsquerya  The 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

    TNr   r,   r2   r/   r   r     r   r2   r   c                  $    e Zd ZdZdZej        ZdS )phraseto_tsquerya  The 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

    TNr   r,   r2   r/   r   r     r   r2   r   c                  $    e Zd ZdZdZej        ZdS )websearch_to_tsquerya  The 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

    TNr   r,   r2   r/   r   r     r   r2   r   c                  *     e Zd ZdZdZeZ fdZ xZS )ts_headlinea  The 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           
         t          |          }t          |          dk     rd}nCt          |d         t          j                  r!|d         j        j        t          j        u rd}nd}|rSt          j
        t          j        |                    d           t           dd           t          j                  }|g}ng } fd|D             } t!                      j        ||z   i | d S )	N   Fr   Tr   r_   )r   r_   r   c                r    g | ]3}t          j        t          j        |t	          d d                    4S r   r   r   s     r/   r|   z(ts_headline.__init__.<locals>.<listcomp>  r   r2   )r   r9   rw   r   r   r%   _type_affinityr   r   r   r7   r   r8   r   r   r   r}   r0   )r.   r   rB   has_regconfigr   r   r   s   `     r/   r0   zts_headline.__init__  s   Dzz t99q==!MMtAw 677	!Q+u}<< "MM M 
	#*+&*T6400o  K '-KKK
 
 
 
 
 
 

 	;3??????r2   )	rO   rP   rQ   rR   r   r   r%   r0   r   r   s   @r/   r   r     sW         " MD&@ &@ &@ &@ &@ &@ &@ &@ &@r2   r   N)2
__future__r   typingr   r   r   r   r   r	   r
    r   arrayr   sqlr   r   r   r   r   r   
sql.schemar   sql.sqltypesr   sql.visitorsr   sql._typingr   sql.elementsr   r   sql.operatorsr   sql.selectabler   r   r   r   r"   r[   r   GenericFunctionr   r   r   r   r   r   r   r,   r2   r/   <module>r      s   # " " " " "                                                                                                 4 4 4 4 4 4             - - - - - - 7888888------------------,,,,,,222222666666WTcG cG cG cG cG1"5 cG cG cGLt t t t t2 t t tn0 0 0@ @ @ @ @I-b1 @ @ @:    -   ,       ,    m   ,    }   ,    =   ,;@ ;@ ;@ ;@ ;@- ;@ ;@ ;@ ;@ ;@r2   