ARRAY, BIGINT, BIT, BOOLEAN, BYTEA, CHAR, CIDR, DATE, \
DOUBLE_PRECISION, ENUM, FLOAT, HSTORE, INET, INTEGER, \
INTERVAL, MACADDR, NUMERIC, REAL, SMALLINT, TEXT, TIME, \
- TIMESTAMP, UUID, VARCHAR
+ TIMESTAMP, UUID, VARCHAR, INT4RANGE, INT8RANGE, NUMRANGE, \
+ DATERANGE, TSRANGE, TSTZRANGE
Types which are specific to PostgreSQL, or have PostgreSQL-specific
construction arguments, are as follows:
:members: __init__
:show-inheritance:
+.. autoclass:: sqlalchemy.dialects.postgresql.ranges.RangeOperators
+ :members:
+
+.. autoclass:: INT4RANGE
+ :show-inheritance:
+
+.. autoclass:: INT8RANGE
+ :show-inheritance:
+
+.. autoclass:: NUMRANGE
+ :show-inheritance:
+
+.. autoclass:: DATERANGE
+ :show-inheritance:
+
+.. autoclass:: TSRANGE
+ :show-inheritance:
+
+.. autoclass:: TSTZRANGE
+ :show-inheritance:
+
+
+PostgreSQL Constraint Types
+---------------------------
+
+SQLAlchemy supports Postgresql EXCLUDE constraints via the
+:class:`ExcludeConstraint` class:
+
+.. autoclass:: ExcludeConstraint
+ :show-inheritance:
+ :members: __init__
+
+For example::
+
+ from sqlalchemy.dialects.postgresql import (
+ ExcludeConstraint,
+ TSRANGE as Range,
+ )
+
+ class RoomBookings(Base):
+
+ room = Column(Integer(), primary_key=True)
+ during = Column(TSRANGE())
+
+ __table_args__ = (
+ ExcludeConstraint(('room', '='), ('during', '&&')),
+ )
+
psycopg2
--------------
from sqlalchemy.sql import expression
class ExcludeConstraint(ColumnCollectionConstraint):
- """A table-level UNIQUE constraint.
+ """A table-level EXCLUDE constraint.
- Defines a single column or composite UNIQUE constraint. For a no-frills,
- single column constraint, adding ``unique=True`` to the ``Column``
- definition is a shorthand equivalent for an unnamed, single column
- UniqueConstraint.
+ Defines an EXCLUDE constraint as described in the `postgres
+ documentation`__.
+
+ __ http://www.postgresql.org/docs/9.0/static/sql-createtable.html#SQL-CREATETABLE-EXCLUDE
"""
__visit_name__ = 'exclude_constraint'
__all__ = ('INT4RANGE', 'INT8RANGE', 'NUMRANGE')
class RangeOperators(object):
+ """
+ This mixin provides functionality for the Range Operators
+ listed in Table 9-44 of the `postgres documentation`__ for Range
+ Functions and Operators. It is used by all the range types
+ provided in the ``postgres`` dialect and can likely be used for
+ any range types you create yourself.
+
+ __ http://www.postgresql.org/docs/devel/static/functions-range.html
+
+ No extra support is provided for the Range Functions listed in
+ Table 9-45 of the postgres documentation. For these, the normal
+ :func:`~sqlalchemy.sql.expression.func` object should be used.
+ """
class comparator_factory(sqltypes.Concatenable.Comparator):
"""Define comparison operations for range types."""