File: //opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyc
�
���ec @ s d d l 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 j
d � Z e j
d
� Z d e j
e j f d � � YZ e j d
d d d e �Z e j d d d d e �Z e j d d d d e �Z d e j f d � � YZ d � Z d S( i����Ni ( t types( t util( t coercions( t
expression( t operators( t rolesc C s | j | | � S( sj A synonym for the ARRAY-level :meth:`.ARRAY.Comparator.any` method.
See that method for details.
( t any( t othert arrexprt operator( ( sU /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyt Any s c C s | j | | � S( sj A synonym for the ARRAY-level :meth:`.ARRAY.Comparator.all` method.
See that method for details.
( t all( R R R ( ( sU /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyt All s t arrayc B sS e Z d Z d Z d Z e Z d � Z e d � � Z e
d d � Z d d � Z
RS( s� 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`
R
t
postgresqlc K s� g | D] } t j t j | � ^ q } t t | � j | | � g | D] } | j ^ qH | _ | j d | j r | j d n t
j � } t | t
� r� t
| j d | j d k r� | j d n d �| _ n t
| � | _ d S( Nt type_i t
dimensionsi i ( R t expectR t ExpressionElementRolet superR
t __init__t typet _type_tuplet popt sqltypest NULLTYPEt
isinstancet ARRAYt item_typeR t None( t selft clausest kwt ct argt main_type( ( sU /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyR \ s (" c C s | f S( N( ( R ( ( sU /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyt _select_iterables s c C sy | s | t j k r@ t j d | d | d | d | j d t �St g | D]$ } | j | | d t d | �^ qJ � Sd S( Nt _compared_to_operatorR t _compared_to_typet uniquet _assume_scalar( R t getitemR t
BindParameterR R t TrueR
t _bind_param( R R t objR( R t o( ( sU /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyR, w s c C s3 | t j t j t j f k r+ t j | � S| Sd S( N( R t any_opt all_opR) R t Grouping( R t against( ( sU /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyt
self_group� s
N( t __name__t
__module__t __doc__t __visit_name__t stringify_dialectR+ t
inherit_cacheR t propertyR$ t FalseR R, R3 ( ( ( sU /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyR
$ s 1 s @>t
precedencei t
is_comparisons <@s &&R c B s� e Z d Z d e j j f d � � YZ e Z e d e d � Z e
d � � Z e
d � � Z d � Z
d � Z e j d � � Z d � Z d
� Z d � Z RS(
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`.
.. 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.
t
Comparatorc B s) e Z d Z d � Z d � Z d � Z RS( s* 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 K s | j t | d t j �S( s� Boolean 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.
t result_type( t operatet CONTAINSR t Boolean( R R t kwargs( ( sU /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyt contains� s c C s | j t | d t j �S( s� Boolean expression. Test if elements are a proper subset of the
elements of the argument array expression.
R? ( R@ t CONTAINED_BYR RB ( R R ( ( sU /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyt contained_by� s c C s | j t | d t j �S( su Boolean expression. Test if array has elements in common with
an argument array expression.
R? ( R@ t OVERLAPR RB ( R R ( ( sU /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyt overlap� s ( R4 R5 R6 RD RF RH ( ( ( sU /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/array.pyR>