
    `?iC                    l   S SK Jr  S SK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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  \	(       aT  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K&J)r)  SSK&J*r*  SS KJ+r+  SS!K,J-r-  \
" S"\S#9r.\
" S$\S#9r/\R`                  4       S,S% jjr\R`                  4       S,S& jjr1 " S' S(\Rd                  \.   5      r3 " S) S*\Rh                  \.   5      r4S-S+ jr5g).    )annotationsN)Any)Iterable)Optional)Sequence)TYPE_CHECKING)TypeVar)Union   )CONTAINED_BY)CONTAINS)OVERLAP   )types)util)
expression)	operators)InternalTraversal)Dialect)_ColumnExpressionArgument)_TypeEngineArgument)ColumnElement)Grouping)BindParameter)OperatorType)_SelectIterable)_BindProcessorType)_LiteralProcessorType)_ResultProcessorType)
TypeEngine)_TraverseInternalsType)Self_T)bound_CTc                $    UR                  X5      $ )zbA synonym for the ARRAY-level :meth:`.ARRAY.Comparator.any` method.
See that method for details.

)anyotherarrexproperators      h/var/www/html/livechat/backend/venv/lib/python3.13/site-packages/sqlalchemy/dialects/postgresql/array.pyr   r   2        ;;u''    c                $    UR                  X5      $ )zbA synonym for the ARRAY-level :meth:`.ARRAY.Comparator.all` method.
See that method for details.

)allr(   s      r,   Allr1   ?   r-   r.   c                     ^  \ rS rSr% SrS rSrS\R                  4S\R                  4/r
S\S'   SS	.     SU 4S
 jjjr\SS j5       r  S         SS jjr S   SS jjrSrU =r$ )arrayL   a  A PostgreSQL ARRAY literal.

This is used to produce ARRAY literals in SQL expressions, e.g.::

    from sqlalchemy.dialects.postgresql import array
    from sqlalchemy.dialects import postgresql
    from sqlalchemy import select, func

    stmt = select(array([1, 2]) + array([3, 4, 5]))

    print(stmt.compile(dialect=postgresql.dialect()))

Produces the SQL:

.. sourcecode:: sql

    SELECT ARRAY[%(param_1)s, %(param_2)s] ||
        ARRAY[%(param_3)s, %(param_4)s, %(param_5)s]) AS anon_1

An instance of :class:`.array` will always have the datatype
:class:`_types.ARRAY`.  The "inner" type of the array is inferred from the
values present, unless the :paramref:`_postgresql.array.type_` keyword
argument is passed::

    array(["foo", "bar"], type_=CHAR)

When constructing an empty array, the :paramref:`_postgresql.array.type_`
argument is particularly important as PostgreSQL server typically requires
a cast to be rendered for the inner type in order to render an empty array.
SQLAlchemy's compilation for the empty array will produce this cast so
that::

    stmt = array([], type_=Integer)
    print(stmt.compile(dialect=postgresql.dialect()))

Produces:

.. sourcecode:: sql

    ARRAY[]::INTEGER[]

As required by PostgreSQL for empty arrays.

.. versionadded:: 2.0.40 added support to render empty PostgreSQL array
   literals with a required cast.

Multidimensional arrays are produced by nesting :class:`.array` constructs.
The dimensionality of the final :class:`_types.ARRAY`
type is calculated by
recursively adding the dimensions of the inner :class:`_types.ARRAY`
type::

    stmt = select(
        array(
            [array([1, 2]), array([3, 4]), array([column("q"), column("x")])]
        )
    )
    print(stmt.compile(dialect=postgresql.dialect()))

Produces:

.. sourcecode:: sql

    SELECT ARRAY[
        ARRAY[%(param_1)s, %(param_2)s],
        ARRAY[%(param_3)s, %(param_4)s],
        ARRAY[q, x]
    ] AS anon_1

.. versionadded:: 1.3.6 added support for multidimensional array literals

.. seealso::

    :class:`_postgresql.ARRAY`


postgresqlclausestyper!   _traverse_internalsN)type_c               ~  > [         TU ]  " [        R                  /UQ70 UD6  Ub  UO9U R                  (       a  U R                  S   R
                  O[        R                  n[        U[        5      (       a6  [        UR                  UR                  b  UR                  S-   OSS9U l        g[        U5      U l        g)zConstruct an ARRAY literal.

:param clauses: iterable, such as a list, containing elements to be
 rendered in the array
:param type\_: optional type.  If omitted, the type is inferred
 from the contents of the array.

Nr   r      )
dimensions)super__init__r   comma_opr6   r7   sqltypesNULLTYPE
isinstanceARRAY	item_typer<   )selfr6   r9   kw	main_type	__class__s        r,   r>   array.__init__   s     	++<g<<   )-a%%8;L;L 	 i''## !++7 ((1,DI i(DIr.   c                    U 4$ N rE   s    r,   _select_iterablearray._select_iterable   s	    wr.   c                    U(       d  U[         R                  L a#  [        R                  " S UUUU R                  SS9$ [        U Vs/ s H  nU R                  XSUS9PM     sn5      $ s  snf )NT)_compared_to_operatorr9   _compared_to_typeunique)_assume_scalarr9   )r   getitemr   r   r7   r3   _bind_param)rE   r+   objr9   rT   os         r,   rV   array._bind_param   s     X):)::++&."&))  
 !	 ! $$ D %  !	 s   A)c                    U[         R                  [         R                  [         R                  4;   a  [        R
                  " U 5      $ U $ rK   )r   any_opall_oprU   r   r   )rE   againsts     r,   
self_grouparray.self_group   s;     y'')9)99;L;LMM&&t,,Kr.   )r7   )r6   zIterable[_T]r9   z!Optional[_TypeEngineArgument[_T]]rF   
typing_Any)returnr   )NF)
r+   r   rW   r`   r9   zOptional[TypeEngine[_T]]rT   boolra   zBindParameter[_T]rK   )r]   zOptional[OperatorType]ra   zUnion[Self, Grouping[_T]])__name__
__module____qualname____firstlineno____doc____visit_name__stringify_dialectr   dp_clauseelement_tupledp_typer8   __annotations__r>   propertyrN   rV   r^   __static_attributes____classcell__)rH   s   @r,   r3   r3   L   s    KZ N$ 
%<<=	"**+3/  48	!)!) 1	!)
 !) !)F   +/$  (	
  
8 15-	" r.   r3   c                      \ rS rSrSr   S       SS jjr " S S\R                  R                  \	   5      r\r
\R                  SS j5       r    SS jr    SS	 jr      SS
 jrSrg)rC      a	  PostgreSQL ARRAY type.

The :class:`_postgresql.ARRAY` type is constructed in the same way
as the core :class:`_types.ARRAY` type; a member type is required, and a
number of dimensions is recommended if the type is to be used for more
than one dimension::

    from sqlalchemy.dialects import postgresql

    mytable = Table(
        "mytable",
        metadata,
        Column("data", postgresql.ARRAY(Integer, dimensions=2)),
    )

The :class:`_postgresql.ARRAY` type provides all operations defined on the
core :class:`_types.ARRAY` type, including support for "dimensions",
indexed access, and simple matching such as
:meth:`.types.ARRAY.Comparator.any` and
:meth:`.types.ARRAY.Comparator.all`.  :class:`_postgresql.ARRAY`
class also
provides PostgreSQL-specific methods for containment operations, including
:meth:`.postgresql.ARRAY.Comparator.contains`
:meth:`.postgresql.ARRAY.Comparator.contained_by`, and
:meth:`.postgresql.ARRAY.Comparator.overlap`, e.g.::

    mytable.c.data.contains([1, 2])

Indexed access is one-based by default, to match that of PostgreSQL;
for zero-based indexed access, set
:paramref:`_postgresql.ARRAY.zero_indexes`.

Additionally, the :class:`_postgresql.ARRAY`
type does not work directly in
conjunction with the :class:`.ENUM` type.  For a workaround, see the
special type at :ref:`postgresql_array_of_enum`.

.. container:: topic

    **Detecting Changes in ARRAY columns when using the ORM**

    The :class:`_postgresql.ARRAY` type, when used with the SQLAlchemy ORM,
    does not detect in-place mutations to the array. In order to detect
    these, the :mod:`sqlalchemy.ext.mutable` extension must be used, using
    the :class:`.MutableList` class::

        from sqlalchemy.dialects.postgresql import ARRAY
        from sqlalchemy.ext.mutable import MutableList


        class SomeOrmClass(Base):
            # ...

            data = Column(MutableList.as_mutable(ARRAY(Integer)))

    This extension will allow "in-place" changes such to the array
    such as ``.append()`` to produce events which will be detected by the
    unit of work.  Note that changes to elements **inside** the array,
    including subarrays that are mutated in place, are **not** detected.

    Alternatively, assigning a new array value to an ORM element that
    replaces the old one will always trigger a change event.

.. seealso::

    :class:`_types.ARRAY` - base array type

    :class:`_postgresql.array` - produces a literal array value.

Nc                    [        U[        5      (       a  [        S5      e[        U[        5      (       a  U" 5       nXl        X l        X0l        X@l        g)au  Construct an ARRAY.

E.g.::

  Column("myarray", ARRAY(Integer))

Arguments are:

:param item_type: The data type of items of this array. Note that
  dimensionality is irrelevant here, so multi-dimensional arrays like
  ``INTEGER[][]``, are constructed as ``ARRAY(Integer)``, not as
  ``ARRAY(ARRAY(Integer))`` or such.

:param as_tuple=False: Specify whether return results
  should be converted to tuples from lists. DBAPIs such
  as psycopg2 return lists by default. When tuples are
  returned, the results are hashable.

:param dimensions: if non-None, the ARRAY will assume a fixed
 number of dimensions.  This will cause the DDL emitted for this
 ARRAY to include the exact number of bracket clauses ``[]``,
 and will also optimize the performance of the type overall.
 Note that PG arrays are always implicitly "non-dimensioned",
 meaning they can store any number of dimensions no matter how
 they were declared.

:param zero_indexes=False: when True, index values will be converted
 between Python zero-based and PostgreSQL one-based indexes, e.g.
 a value of one will be added to all index values before passing
 to the database.

zUDo not nest ARRAY types; ARRAY(basetype) handles multi-dimensional arrays of basetypeN)rB   rC   
ValueErrorr7   rD   as_tupler<   zero_indexes)rE   rD   rt   r<   ru   s        r,   r>   ARRAY.__init__6  sO    N i''?  i&&!I" $(r.   c                  B    \ rS rSrSr      SS jrS	S jrS	S jrSrg)
ARRAY.Comparatorii  a  Define comparison operations for :class:`_types.ARRAY`.

Note that these operations are in addition to those provided
by the base :class:`.types.ARRAY.Comparator` class, including
:meth:`.types.ARRAY.Comparator.any` and
:meth:`.types.ARRAY.Comparator.all`.

c                H    U R                  [        U[        R                  S9$ )zBoolean expression.  Test if elements are a superset of the
elements of the argument array expression.

kwargs may be ignored by this operator but are required for API
conformance.
result_type)operater   r@   Boolean)rE   r)   kwargss      r,   containsARRAY.Comparator.containss  s     <<%X=M=M<NNr.   c                H    U R                  [        U[        R                  S9$ )zlBoolean expression.  Test if elements are a proper subset of the
elements of the argument array expression.
rz   )r|   r   r@   r}   rE   r)   s     r,   contained_byARRAY.Comparator.contained_by~  s'     <<e1A1A    r.   c                H    U R                  [        U[        R                  S9$ )z]Boolean expression.  Test if array has elements in common with
an argument array expression.
rz   )r|   r   r@   r}   r   s     r,   overlapARRAY.Comparator.overlap  s     <<H<L<L<MMr.   rL   N)r)   r`   r~   r`   ra   ColumnElement[bool])r)   r`   ra   r   )	rc   rd   re   rf   rg   r   r   r   rn   rL   r.   r,   
Comparatorrx   i  s3    			O#		O/9		O 		O		Nr.   r   c                    [        U R                  [        R                  5      =(       a    U R                  R                  $ rK   )rB   rD   r@   Enumnative_enumrM   s    r,   _against_native_enumARRAY._against_native_enum  s-     t~~x}}5 +**	
r.   c                   ^ ^^ T R                   R                  U5      R                  U5      mTc  g SS jmSUU U4S jjnU$ )Nc                ,    SSR                  U 5       S3$ )NzARRAY[z, ])join)elementss    r,   to_str'ARRAY.literal_processor.<locals>.to_str  s    DIIh/022r.   c                D   > TR                  U TTR                  T5      nU$ rK   )_apply_item_processorr<   )valueinner	item_procrE   r   s     r,   process(ARRAY.literal_processor.<locals>.process  s'    ..y$//6E Lr.   )r   zIterable[typing_Any]ra   str)r   Sequence[typing_Any]ra   r   )rD   dialect_implliteral_processor)rE   dialectr   r   r   s   `  @@r,   r   ARRAY.literal_processor  sH     NN//8JJ
	 	3	 	 r.   c                x   ^ ^ T R                   R                  U5      R                  U5      m    SUU 4S jjnU$ )Nc                R   > U c  U $ TR                  U TTR                  [        5      $ rK   )r   r<   listr   r   rE   s    r,   r   %ARRAY.bind_processor.<locals>.process  s/     }119doot r.   )r   Optional[Sequence[typing_Any]]ra   zOptional[list[typing_Any]])rD   r   bind_processor)rE   r   r   r   s   `  @r,   r   ARRAY.bind_processor  sH     NN//8GG
		1	'	 	 r.   c                   ^ ^^^^ T R                   R                  U5      R                  X5      m    SUU 4S jjnT R                  (       a-  Um[        R
                  " S5      mSU4S jjm    SUU4S jjnU$ )Nc                   > U c  U $ TR                  U TTR                  TR                  (       a
  [        5      $ [        5      $ rK   )r   r<   rt   tupler   r   s    r,   r   'ARRAY.result_processor.<locals>.process  sG     }11OO!]]E	  15	 r.   z^{(.*)}$c                Z   > TR                  U 5      R                  S5      n[        U5      $ )Nr   )matchgroup_split_enum_values)r   r   patterns     r,   handle_raw_string1ARRAY.result_processor.<locals>.handle_raw_string  s'    e,2215)%00r.   c                `   > U c  U $ T" [        U [        5      (       a  T" U 5      5      $ U 5      $ rK   )rB   r   )r   r   super_rps    r,   r   r     sD     = L  !%-- &e,   r.   )r   r   ra   r   )r   r   ra   Sequence[Optional[str]])rD   r   result_processorr   recompile)rE   r   coltyper   r   r   r   r   s   `   @@@@r,   r   ARRAY.result_processor  s     NN//8II
		'	+	 	 $$Hjj-G1+/  r.   )rt   r<   rD   ru   )FNF)rD   z_TypeEngineArgument[_T]rt   rb   r<   zOptional[int]ru   rb   )ra   rb   )r   r   ra   z#Optional[_LiteralProcessorType[_T]])r   r   ra   z2Optional[_BindProcessorType[Sequence[typing_Any]]])r   r   r   objectra   z*_ResultProcessorType[Sequence[typing_Any]])rc   rd   re   rf   rg   r>   r@   rC   r   r%   comparator_factoryr   memoized_propertyr   r   r   r   rn   rL   r.   r,   rC   rC      s    ET $("1)*1) 1) "	1)
 1)f!NX^^..s3 !NF $	
 
	,(	;&**)/*	3*r.   rC   c                   SU ;  a3  U (       a  U R                  S5      O/  Vs/ s H  nUS:w  a  UOS PM     sn$ U R                  SS5      nUR                  SS5      n/ n[        R                   " SU5      nS	nU H{  nUS:X  a	  U(       + nM  U(       a#  UR                  UR                  SS5      5        M<  UR	                  [        R
                  " S
U5       Vs/ s H  nUS:w  a  UOS PM     sn5        M}     U$ s  snf s  snf )N",NULLz\"z_$ESC_QUOTE$_z\\\z(")Fz([^\s,]+),?)splitreplacer   appendextendfindall)array_stringrtextresult	on_quotes	in_quotestoks          r,   r   r     s   
, 2>l((-2E
E fA$&E
 	
 7D<<t$DF&II#:%IMM#++os;< MM  ZZ<< fA$.<  M7
,s   C<D
)r)   r`   r*   z_ColumnExpressionArgument[_T]r+   r   ra   r   )r   r   ra   r   )6
__future__r   r   typingr   r`   r   r   r   r   r	   r
   r   r   r   r    r   r@   r   sqlr   sql.visitorsr   engine.interfacesr   sql._typingr   r   sql.elementsr   r   sql.expressionr   sql.operatorsr   sql.selectabler   sql.type_apir   r   r   r    r!   util.typingr"   r#   r%   eqr1   ExpressionClauseListr3   rC   r   rL   r.   r,   <module>r      s   # 	 $        #   !    -,82-(/-1254*6# T$e:& '\\
(
(*
( 
( 	
(  '\\
(
(*
( 
( 	
(_J++B/ _DxHNN2 xvr.   