ó ÃÌ4]c@s(ddlmZddlmZddlmZddlmZddlmZyddl m Z Wne k r}dZ nXejd „Zejd „Zd ejfd „ƒYZejd ddƒZejdddƒZejdddƒZdejfd„ƒYZeeejt precedenceis<@s&&RcBs„eZdZdejjfd„ƒYZeZed ed„Z e d„ƒZ e d„ƒZ d„Z d„Zd„Zd „ZRS( s–PostgreSQL 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. t ComparatorcBs)eZdZd„Zd„Zd„ZRS(s$Define comparison operations for :class:`.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`. cKs|jt|dtjƒS(sBoolean expression. Test if elements are a superset of the elements of the argument array expression. t result_type(toperatetCONTAINStsqltypestBoolean(RRtkwargs((sW/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pytcontainsÐscCs|jt|dtjƒS(s„Boolean expression. Test if elements are a proper subset of the elements of the argument array expression. R0(R1t CONTAINED_BYR3R4(RR((sW/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyt contained_byÖscCs|jt|dtjƒS(suBoolean expression. Test if array has elements in common with an argument array expression. R0(R1tOVERLAPR3R4(RR((sW/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pytoverlapÞs(R)R*R+R6R8R:(((sW/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyR/Ås   cCsat|tƒrtdƒ‚nt|tƒr9|ƒ}n||_||_||_||_dS(sPConstruct 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. .. versionadded:: 0.9.5 sUDo not nest ARRAY types; ARRAY(basetype) handles multi-dimensional arrays of basetypeN(RRt ValueErrorRRtas_tupleRt zero_indexes(RRR<RR=((sW/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyRæs&     cCs|jS(N(R<(R((sW/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pythashablescCstS(N(tlist(R((sW/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyt python_typescCs ||kS(N((Rtxty((sW/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pytcompare_values scs¨ˆdkrt|ƒ}nˆdksTˆdkr| sTt|dttfƒ rˆrtˆ‡fd†|DƒƒSˆ|ƒSn#ˆ‡‡‡‡fd†|DƒƒSdS(Niic3s|]}ˆ|ƒVqdS(N((t.0RA(titemproc(sW/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pys 2sc3s=|]3}ˆj|ˆˆdk r+ˆdndˆƒVqdS(iN(t _proc_arrayR(RDRA(t collectiontdimRER(sW/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pys 7s(RR?Rttuple(RtarrRERHRG((RGRHRERsW/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyRF#s    cs1ˆjj|ƒj|ƒ‰‡‡fd†}|S(Ncs-|dkr|Sˆj|ˆˆjtƒSdS(N(RRFRR?(tvalue(t item_procR(sW/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pytprocessEs (Rt dialect_impltbind_processor(RtdialectRM((RLRsW/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyRO@s cs4ˆjj|ƒj||ƒ‰‡‡fd†}|S(Ncs<|dkr|Sˆj|ˆˆjˆjr1tntƒSdS(N(RRFRR<RIR?(RK(RLR(sW/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyRMTs (RRNtresult_processor(RRPtcoltypeRM((RLRsW/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyRQOs  N(R)R*R+R3RR/tcomparator_factoryR-RRtpropertyR>R@RCRFRORQ(((sW/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyR˜s+1   t_arrayN(tbaseRRtRR3tsqlRRtuuidRt _python_UUIDt ImportErrorRteqR R tTupleR t custom_opR2R7R9R(((sW/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyts"  `Ê