summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Withers <chris@simplistix.co.uk>2013-06-10 13:24:02 +0100
committerChris Withers <chris@simplistix.co.uk>2013-06-10 13:24:02 +0100
commitb2da12e070e9d83bea5284dae11b8e6d4d509818 (patch)
tree2feac282d4b53875b0ddcc95b0b26768a7c668da
parentb2ea2eef5db160183cd4f812b0ce1636d8799b91 (diff)
downloadsqlalchemy-pr/5.tar.gz
Documentation for the new range type support.pr/5
-rw-r--r--doc/build/dialects/postgresql.rst51
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py2
-rw-r--r--lib/sqlalchemy/dialects/postgresql/constraints.py10
-rw-r--r--lib/sqlalchemy/dialects/postgresql/ranges.py13
4 files changed, 69 insertions, 7 deletions
diff --git a/doc/build/dialects/postgresql.rst b/doc/build/dialects/postgresql.rst
index df141cce0..f2b401e9a 100644
--- a/doc/build/dialects/postgresql.rst
+++ b/doc/build/dialects/postgresql.rst
@@ -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
--------------
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index 4a6de0ceb..238a8af8f 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -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)
diff --git a/lib/sqlalchemy/dialects/postgresql/constraints.py b/lib/sqlalchemy/dialects/postgresql/constraints.py
index 88d688a05..5b8bbe643 100644
--- a/lib/sqlalchemy/dialects/postgresql/constraints.py
+++ b/lib/sqlalchemy/dialects/postgresql/constraints.py
@@ -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'
diff --git a/lib/sqlalchemy/dialects/postgresql/ranges.py b/lib/sqlalchemy/dialects/postgresql/ranges.py
index 2054ef137..e7ab1d5b5 100644
--- a/lib/sqlalchemy/dialects/postgresql/ranges.py
+++ b/lib/sqlalchemy/dialects/postgresql/ranges.py
@@ -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."""