]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Documentation for the new range type support.
authorChris Withers <chris@simplistix.co.uk>
Mon, 10 Jun 2013 12:24:02 +0000 (13:24 +0100)
committerChris Withers <chris@simplistix.co.uk>
Mon, 10 Jun 2013 12:24:02 +0000 (13:24 +0100)
doc/build/dialects/postgresql.rst
lib/sqlalchemy/dialects/postgresql/base.py
lib/sqlalchemy/dialects/postgresql/constraints.py
lib/sqlalchemy/dialects/postgresql/ranges.py

index df141cce00cc7acc7547dde628a7641c93f503d2..f2b401e9a57176695a8640fd71e86080fab1cd24 100644 (file)
@@ -16,7 +16,8 @@ they originate from :mod:`sqlalchemy.types` or from the local dialect::
         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:
@@ -81,6 +82,54 @@ 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
 --------------
 
index 4a6de0ceb96f8e684b7872d21d338a7cf6e33b4c..238a8af8f44a4467f3166feda2cf84626e51b984 100644 (file)
@@ -426,7 +426,7 @@ class array(expression.Tuple):
 
     An instance of :class:`.array` will always have the datatype
     :class:`.ARRAY`.  The "inner" type of the array is inferred from
-    the values present, unless the "type_" keyword argument is passed::
+    the values present, unless the ``type_`` keyword argument is passed::
 
         array(['foo', 'bar'], type_=CHAR)
 
index 88d688a05903f81c17eb1b22bd1030d411b42f9c..5b8bbe64303a7340617dad3f6bfefe685ee93cd3 100644 (file)
@@ -6,12 +6,12 @@ from sqlalchemy.schema import ColumnCollectionConstraint
 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'
index 2054ef137429624ab44ad50fb564978b82ba23e0..e7ab1d5b535d30a7b439b854175ccd0913e8fc7c 100644 (file)
@@ -9,6 +9,19 @@ from ... import types as sqltypes
 __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."""