id.ddlZddlmZddlmZddlmZddlmZejfdZ ejfdZ Gd d ej Z ej d d Zej dd Zej dd ZGddejZdS)N)types)util) expression) operatorsc.|||S)zA synonym for the :meth:`.ARRAY.Comparator.any` method. This method is legacy and is here for backwards-compatibility. .. seealso:: :func:`_expression.any_` )anyotherarrexproperators Y/opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/array.pyAnyr ;;uh ' ''c.|||S)zA synonym for the :meth:`.ARRAY.Comparator.all` method. This method is legacy and is here for backwards-compatibility. .. seealso:: :func:`_expression.all_` )allr s rAllrrrc6eZdZdZdZfdZddZddZxZS) arraya 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:: 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 ``type_`` keyword argument is passed:: array(['foo', 'bar'], type_=CHAR) 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:: 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` c (tt|j|i|t|jt r=t |jj|jj|jjdznd|_dSt |j|_dS)N) dimensions)superr__init__ isinstancetypeARRAY item_typer)selfclauseskw __class__s rrzarray.__init__cs#eT#W3333 di ' ' ) #9'3 9/!33 DIIIdi((DIIIrFNc|stjurtjd|jdSt fd|DS)NT)_compared_to_operatortype__compared_to_typeuniquecBg|]}|dS)T)_assume_scalarr') _bind_param).0or r!r's r z%array._bind_param..|sI$$ !D%r)rgetitemr BindParameterrr)r!r objr+r's`` `rr,zarray._bind_paramos  X):::+&."&)  !  rcx|tjtjtjfvrt j|S|SN)rany_opall_opr0rGrouping)r!againsts r self_groupzarray.self_groups3 y')99;LM M M&t,, ,Kr)FNr4) __name__ __module__ __qualname____doc____visit_name__rr,r9 __classcell__)r$s@rrr,sr11fN ) ) ) ) )*rrz@>) precedencez<@z&&ceZdZdZGddejjZeZ ddZe dZ e dZ d Z d Z ejd Zd Zd ZdZdS)raPostgreSQL ARRAY type. .. versionchanged:: 1.1 The :class:`_postgresql.ARRAY` type is now a subclass of the core :class:`_types.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]) The :class:`_postgresql.ARRAY` type may not be supported on all PostgreSQL DBAPIs; it is currently known to work on psycopg2 only. 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`. .. seealso:: :class:`_types.ARRAY` - base array type :class:`_postgresql.array` - produces a literal array value. c$eZdZdZdZdZdZdS)ARRAY.Comparatora*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 P|t|tjS)zBoolean expression. Test if elements are a superset of the elements of the argument array expression.  result_type)operateCONTAINSsqltypesBoolean)r!r kwargss rcontainszARRAY.Comparator.containss<<%X=M<NN NrcP|t|tjS)zBoolean expression. Test if elements are a proper subset of the elements of the argument array expression. rF)rH CONTAINED_BYrJrKr!r s r contained_byzARRAY.Comparator.contained_bys)<<e1A  rcP|t|tjS)zuBoolean expression. Test if array has elements in common with an argument array expression. rF)rHOVERLAPrJrKrPs roverlapzARRAY.Comparator.overlaps<<Hz$ARRAY._proc_array...s+!;!;!((1++!;!;!;!;!;!;rc3VK|]#}|dz ndV$dS)Nr) _proc_array)r-rb collectiondimrgr!s rrhz$ARRAY._proc_array..2sa   "C!GGD r)r_rtuple)r!arrrgrlrks` ```rrjzARRAY._proc_arrays ;s))C 1HH{   "#a&4-88  '!z!;!;!;!;s!;!;!;;;;!z#&: rcXt|jtjo |jjSr4)rr rJEnum native_enumr\s r_against_native_enumzARRAY._against_native_enum<s' t~x} 5 5 +* rc|Sr4rU)r! bindvalues rbind_expressionzARRAY.bind_expressionCsrcpj||fd}|S)NcP||S|jtSr4)rjrr_value item_procr!s rprocessz%ARRAY.bind_processor..processKs0} ''9dotr)r dialect_implbind_processor)r!dialectr{rzs` @rr}zARRAY.bind_processorFsQN//88GG         rcj|||fd}jr |dfd}|S)Ncl||S|jjrtntSr4)rjrrYrmr_rxs rr{z'ARRAY.result_processor..processZs>} ''O!]4EE rctjd|d}|r|dngS)Nz^{(.*)}$r,)rematchgroupsplit)ryinners rhandle_raw_stringz1ARRAY.result_processor..handle_raw_stringhs=e44::1==+08u{{3'''b8rcl||St|tjr |n|Sr4)rr string_types)ryrsuper_rps rr{z'ARRAY.result_processor..processlsL= L x!%):;;%%e,,,r)r r|result_processorrr)r!r~coltyper{rrzrs` @@@rrzARRAY.result_processorUsN//88II W          $ H 9 9 9      r)FNF)r:r;r<r=rJrrVcomparator_factoryrpropertyr]r`rdrjrmemoized_propertyrrrur}rrUrrrrs++ZNNNNNX^.NNN>$HM0)0)0)0)dXX:       #####rr)rrrJrsqlrreqrrTupler custom_oprIrOrSrrUrrrsK !!!!!!"+ ( ( ( ("+ ( ( ( (\\\\\J \\\~ 9 t 2 2 2"y"4A666 ) dq 1 1 1fffffHNfffffr