summaryrefslogtreecommitdiff
path: root/doc/build/dialects
diff options
context:
space:
mode:
authorChris Withers <chris@withers.org>2014-05-25 15:46:31 +0100
committerChris Withers <chris@withers.org>2014-05-25 15:46:31 +0100
commit551c730f3fee058f68a813b5f0eadce0c8a2820a (patch)
treed1185ee2afe1472c0449c300b3952ecb71be771c /doc/build/dialects
parent8a4f75e9721beb93483b0ff8283ffbb0d6018ec3 (diff)
downloadsqlalchemy-551c730f3fee058f68a813b5f0eadce0c8a2820a.tar.gz
more docs for using psycopg2 range types, specifically instantiating models with them
Diffstat (limited to 'doc/build/dialects')
-rw-r--r--doc/build/dialects/postgresql.rst31
1 files changed, 30 insertions, 1 deletions
diff --git a/doc/build/dialects/postgresql.rst b/doc/build/dialects/postgresql.rst
index 05b63506e..c466f0377 100644
--- a/doc/build/dialects/postgresql.rst
+++ b/doc/build/dialects/postgresql.rst
@@ -126,6 +126,33 @@ mixin:
``psycopg2``, it's recommended to upgrade to version 2.5 or later
before using these column types.
+When instantiating models that use these column types, you should pass
+whatever data type is expected by the DBAPI driver you're using for
+the column type. For :mod:`psycopg2` these are
+:class:`~psycopg2.extras.NumericRange`,
+:class:`~psycopg2.extras.DateRange`,
+:class:`~psycopg2.extras.DateTimeRange` and
+:class:`~psycopg2.extras.DateTimeTZRange` or the class you've
+registered with :func:`~psycopg2.extras.register_range`.
+
+For example:
+
+.. code-block:: python
+
+ from psycopg2.extras import DateTimeRange
+ from sqlalchemy.dialects.postgresql import TSRANGE
+
+ class RoomBooking(Base):
+
+ __tablename__ = 'room_booking'
+
+ room = Column(Integer(), primary_key=True)
+ during = Column(TSRANGE())
+
+ booking = RoomBooking(
+ room=101,
+ during=DateTimeRange(datetime(2013, 3, 23), None
+ )
PostgreSQL Constraint Types
---------------------------
@@ -140,7 +167,9 @@ For example::
from sqlalchemy.dialects.postgresql import ExcludeConstraint, TSRANGE
- class RoomBookings(Base):
+ class RoomBooking(Base):
+
+ __tablename__ = 'room_booking'
room = Column(Integer(), primary_key=True)
during = Column(TSRANGE())