The PostgreSQL dialect fully supports SAVEPOINT and two-phase commit operations.
+Arrays
+------
+
+The PostgreSQL dialect supports ``ARRAY`` types with the :class:`~sqlalchemy.databases.postgres.PGArray` datatype::.
+E.g. to represent ``INTEGER[]``, use ``PGArray(Integer)``. This is also the
+correct type representation for ``INTEGER[][]`` and ``INTEGER[3][][4]``, so
+dimensionality and range limits do not matter. (In particular, do not
+try to represent ``INTEGER[][]`` with ``PGArray(PGArray(Integer))``.)
+
"""
return "DOUBLE PRECISION"
class PGArray(sqltypes.MutableType, sqltypes.Concatenable, sqltypes.TypeEngine):
+ """PostgreSQL ARRAY type."""
def __init__(self, item_type, mutable=True):
+ """Construct an ARRAY.
+
+ Example:
+
+ Column('myarray', PGArray(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 `PGArray(Integer)`, not as
+ `PGArray(PGArray(Integer))` or such. The type mapping figures out on the fly
+ :param mutable: Defaults to True: specify whether lists passed to this class should be considered mutable.
+ If so, then they are shallow-copied.
+ """
if isinstance(item_type, type):
item_type = item_type()
+ if isinstance(item_type, PGArray):
+ raise ValueError('Do not nest PGArray types; PGArray(basetype) handles multi-dimensional arrays of basetype')
self.item_type = item_type
self.mutable = mutable
from generic to database-specific.
Subclasses will usually use the
- :func:`~sqlalchemy.types.adapt_type` method in the types module to
+ :func:`~sqlalchemy.types.adapt_type()` function in the types module to
make this job easy.
"""
raise NotImplementedError()
+ def get_rowcount(self):
+ """Return the number of rows produced (by a SELECT query)
+ or affected (by an INSERT/UPDATE/DELETE statement).
+
+ Note that this row count may not be properly implemented in some dialects;
+ this is indicated by :meth:`supports_sane_rowcount` and
+ :meth:`supports_sane_multi_rowcount`
+ """
+
+ raise NotImplementedError()
+
class Compiled(object):
"""Represent a compiled SQL expression.
@property
def rowcount(self):
+ """Return ``get_rowcount()`` from the underlying ExecutionContext.
+
+ See ExecutionContext for details.
+
+ Note that this row count may not be properly implemented in some dialects;
+ this is indicated by :meth:`~sqlalchemy.engine.base.ResultProxy.supports_sane_rowcount`
+ and :meth:`~sqlalchemy.engine.base.ResultProxy.supports_sane_multi_rowcount`
+ """
if self._rowcount is None:
return self.context.get_rowcount()
else: