~ubuntu-branches/debian/sid/sqlalchemy/sid

« back to all changes in this revision

Viewing changes to doc/build/dialects/postgresql.rst

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2014-06-27 20:17:13 UTC
  • mfrom: (1.4.28)
  • Revision ID: package-import@ubuntu.com-20140627201713-g6p1kq8q1qenztrv
Tags: 0.9.6-1
* New upstream release
* Remove Python 3.X build tag files, thanks to Matthias Urlichs for the
  patch (closes: #747852)
* python-fdb isn't in the Debian archive yet so default dialect for firebird://
  URLs is changed to obsolete kinterbasdb, thanks to Russell Stuart for the
  patch (closes: #752145)

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
    from sqlalchemy.dialects.postgresql import \
16
16
        ARRAY, BIGINT, BIT, BOOLEAN, BYTEA, CHAR, CIDR, DATE, \
17
17
        DOUBLE_PRECISION, ENUM, FLOAT, HSTORE, INET, INTEGER, \
18
 
        INTERVAL, JSON, MACADDR, NUMERIC, REAL, SMALLINT, TEXT, TIME, \
 
18
        INTERVAL, JSON, MACADDR, NUMERIC, OID, REAL, SMALLINT, TEXT, TIME, \
19
19
        TIMESTAMP, UUID, VARCHAR, INT4RANGE, INT8RANGE, NUMRANGE, \
20
20
        DATERANGE, TSRANGE, TSTZRANGE, TSVECTOR
21
21
 
78
78
.. autoclass:: MACADDR
79
79
    :members: __init__
80
80
 
 
81
.. autoclass:: OID
 
82
    :members: __init__
81
83
 
82
84
.. autoclass:: REAL
83
85
    :members: __init__
126
128
  ``psycopg2``, it's recommended to upgrade to version 2.5 or later
127
129
  before using these column types.
128
130
 
 
131
When instantiating models that use these column types, you should pass
 
132
whatever data type is expected by the DBAPI driver you're using for
 
133
the column type. For :mod:`psycopg2` these are
 
134
:class:`~psycopg2.extras.NumericRange`,
 
135
:class:`~psycopg2.extras.DateRange`,
 
136
:class:`~psycopg2.extras.DateTimeRange` and
 
137
:class:`~psycopg2.extras.DateTimeTZRange` or the class you've
 
138
registered with :func:`~psycopg2.extras.register_range`.
 
139
 
 
140
For example:
 
141
 
 
142
.. code-block:: python
 
143
 
 
144
  from psycopg2.extras import DateTimeRange
 
145
  from sqlalchemy.dialects.postgresql import TSRANGE
 
146
 
 
147
  class RoomBooking(Base):
 
148
 
 
149
      __tablename__ = 'room_booking'
 
150
 
 
151
      room = Column(Integer(), primary_key=True)
 
152
      during = Column(TSRANGE())
 
153
 
 
154
  booking = RoomBooking(
 
155
      room=101,
 
156
      during=DateTimeRange(datetime(2013, 3, 23), None)
 
157
  )
129
158
 
130
159
PostgreSQL Constraint Types
131
160
---------------------------
140
169
 
141
170
  from sqlalchemy.dialects.postgresql import ExcludeConstraint, TSRANGE
142
171
 
143
 
  class RoomBookings(Base):
 
172
  class RoomBooking(Base):
 
173
 
 
174
      __tablename__ = 'room_booking'
144
175
 
145
176
      room = Column(Integer(), primary_key=True)
146
177
      during = Column(TSRANGE())