.. changelog::
:version: 1.0.10
+ .. change::
+ :tags: bug, postgresql
+ :versions: 1.1.0b1
+ :tickets: 3571
+
+ Fixed the ``.python_type`` attribute of :class:`.postgresql.INTERVAL`
+ to return ``datetime.timedelta`` in the same way as that of
+ :obj:`.types.Interval.python_type`, rather than raising
+ ``NotImplementedError``.
+
.. change::
:tags: bug, mssql
:pullreq: github:213
"""
from collections import defaultdict
import re
+import datetime as dt
+
from ... import sql, schema, exc, util
from ...engine import default, reflection
def _type_affinity(self):
return sqltypes.Interval
+ @property
+ def python_type(self):
+ return dt.timedelta
+
PGInterval = INTERVAL
)
+class PythonTypeTest(fixtures.TestBase):
+ def test_interval(self):
+ is_(
+ postgresql.INTERVAL().python_type,
+ datetime.timedelta
+ )
+
+
class TimezoneTest(fixtures.TestBase):
__backend__ = True
result = connection.execute(s).first()
eq_(result[0], datetime.datetime(2007, 12, 25, 0, 0))
+ def test_interval_arithmetic(self):
+ # basically testing that we get timedelta back for an INTERVAL
+ # result. more of a driver assertion.
+ engine = testing.db
+ connection = engine.connect()
+
+ s = select([text("timestamp '2007-12-25' - timestamp '2007-11-15'")])
+ result = connection.execute(s).first()
+ eq_(result[0], datetime.timedelta(40))
+
class SpecialTypesTest(fixtures.TestBase, ComparesTables, AssertsCompiledSQL):