L iCdddlmZddlZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z d d l m Z d d l mZd d l mZddlmZddlmZddlmZddlm Z ddlmZe rTddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z'ddl&m(Z(ddl&m)Z)ddl&m*Z*dd lm+Z+dd!l,m-Z-e d"e#Z.e d$e#Z/e j`f d,d%Ze j`f d,d&Z1Gd'd(ejde.Z3Gd)d*ejhe.Z4d-d+Z5y).) 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&|j||S)zjA synonym for the ARRAY-level :meth:`.ARRAY.Comparator.any` method. See that method for details. )anyotherarrexproperators j/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/dialects/postgresql/array.pyrr2 ;;uh ''c&|j||S)zjA synonym for the ARRAY-level :meth:`.ARRAY.Comparator.all` method. See that method for details. )allr(s r,Allr1?r-r.ceZdZUdZdZdZdejfdejfgZ de d<dd d fd Z e dd Z d dd Z d dd ZxZS)arrayaA 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` postgresqlclausestyper!_traverse_internalsN)type_c jt|tjg|i|||n4|jr|jdj nt j}t|tr8t|j|j|jdznd|_yt||_y)aConstruct 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. Nrr ) dimensions) super__init__rcomma_opr5r6sqltypesNULLTYPE isinstanceARRAY item_typer;)selfr5r8kw main_type __class__s r,r=zarray.__init__s ++.to_strsDIIh/02 2r.cDj|j}|SrI)_apply_item_processorr;)valueinner item_procrDrs r,processz(ARRAY.literal_processor..processs'..y$//6ELr.)rzIterable[typing_Any]r\str)rSequence[typing_Any]r\r)rC dialect_implliteral_processor)rDdialectrrrs` @@r,rzARRAY.literal_processorsCNN//8JJ     3  r.ctjj|j| dfd }|S)NcP||Sj|jtSrI)rr;listrrrDs r,rz%ARRAY.bind_processor..processs/} 119dootr.)rOptional[Sequence[typing_Any]]r\zOptional[list[typing_Any]])rCrbind_processor)rDrrrs` @r,rzARRAY.bind_processorsCNN//8GG   1  ' r.cjj|j|| dfd }jr(|t j ddfd  dfd }|S)Nc|||Sj|jjr tStSrI)rr;rltuplerrs r,rz'ARRAY.result_processor..processsG} 11OO!]]E 15 r.z^{(.*)}$cZj|jd}t|S)Nr )matchgroup_split_enum_values)rrpatterns r,handle_raw_stringz1ARRAY.result_processor..handle_raw_strings' e,2215)%00r.cT||St|tr |S|SrI)rAr)rrsuper_rps r,rz'ARRAY.result_processor..processsA= L !%-&e,r.)rrr\r)rrr\Sequence[Optional[str]])rCrresult_processorrrecompile)rDrcoltyperrrrrs` @@@@r,rzARRAY.result_processors}NN//8II W  '  +   $ $Hjj-G 1 + / r.)FNF)rCz_TypeEngineArgument[_T]rlr]r;z Optional[int]rmr])r\r])rrr\z#Optional[_LiteralProcessorType[_T]])rrr\z2Optional[_BindProcessorType[Sequence[typing_Any]]])rrrobjectr\z*_ResultProcessorType[Sequence[typing_Any]])r^r_r`rar=r?rBr}r%comparator_factoryrmemoized_propertyrrrrrJr.r,rBrBsET$(" 1)*1)1)" 1)  1)f!NX^^..s3!NF$    ,( ;&**)/* 3*r.rBcd|vr*|r|jdngDcgc] }|dk7r|nd c}S|jdd}|jdd}g}tjd|}d }|D]i}|dk(r| } |r"|j|jdd0|j tj d |Dcgc] }|dk7r|nd c}k|Scc}wcc}w) N",NULLz\"z _$ESC_QUOTE$_z\\\z(")Fz ([^\s,]+),?)splitreplacerappendextendfindall) array_stringrtextresult on_quotes in_quotestoks r,rrs ,2>l((-2 fA$ &      7D <<t $D F&II  #:% I  MM#++os; < MM ZZ<fA$.   M7 ,s CC" )r)r[r*z_ColumnExpressionArgument[_T]r+rr\r|)rrr\r)6 __future__rrtypingrr[rrrrr r rr r rrr?rsqlr sql.visitorsrengine.interfacesr sql._typingrr sql.elementsrrsql.expressionr sql.operatorsrsql.selectabler sql.type_apirrrr r! util.typingr"r#r%eqr1ExpressionClauseListr3rBrrJr.r,rs# $ #!-,82-(/-1254*6# T$ e:& '\\ (  ( * ( ( ( '\\ (  ( * ( ( (_J + +B /_DxHNN2 xvr.