summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2009-12-29 16:11:16 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2009-12-29 16:11:16 +0000
commit17958b5b472e73dcf614f602b238106092157bcd (patch)
tree1c8aa5e0b72e813a9d9d692202fa17f8150aaeba
parent0ef880957534e7447376707a1c145b7496cb6102 (diff)
downloadsqlalchemy-17958b5b472e73dcf614f602b238106092157bcd.tar.gz
make sure the native pg types work too
-rw-r--r--lib/sqlalchemy/databases/postgres.py6
-rw-r--r--test/dialect/test_postgres.py14
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py
index 6605eebd9..51c7401fe 100644
--- a/lib/sqlalchemy/databases/postgres.py
+++ b/lib/sqlalchemy/databases/postgres.py
@@ -166,7 +166,11 @@ class PGTime(sqltypes.Time):
class PGInterval(sqltypes.TypeEngine):
def get_col_spec(self):
return "INTERVAL"
-
+
+ @property
+ def _type_affinity(self):
+ return sqltypes.Interval
+
class PGText(sqltypes.Text):
def get_col_spec(self):
return "TEXT"
diff --git a/test/dialect/test_postgres.py b/test/dialect/test_postgres.py
index a53dc64f5..096a4b8e0 100644
--- a/test/dialect/test_postgres.py
+++ b/test/dialect/test_postgres.py
@@ -62,7 +62,10 @@ class CompileTest(TestBase, AssertsCompiledSQL):
def test_extract(self):
- t = table('t', column('col1', DateTime), column('col2', Date), column('col3', Time))
+ t = table('t', column('col1', DateTime), column('col2', Date), column('col3', Time),
+ column('col4', postgres.PGDateTime), column('col5', postgres.PGDate),
+ column('col6', postgres.PGTime), column('col7', postgres.PGInterval)
+ )
for field in 'year', 'month', 'day', 'epoch', 'hour':
for expr, compiled_expr in [
@@ -84,6 +87,9 @@ class CompileTest(TestBase, AssertsCompiledSQL):
(t.c.col2 + t.c.col3,
"(t.col2 + t.col3) :: timestamp"
),
+ (t.c.col5 + t.c.col6,
+ "(t.col5 + t.col6) :: timestamp"
+ ),
# addition is commutative
(t.c.col2 + datetime.timedelta(days=5),
"(t.col2 + %(col2_1)s) :: timestamp"
@@ -91,6 +97,9 @@ class CompileTest(TestBase, AssertsCompiledSQL):
(datetime.timedelta(days=5) + t.c.col2,
"(%(col2_1)s + t.col2) :: timestamp"
),
+ (t.c.col4 + t.c.col7,
+ "(t.col4 + t.col7) :: timestamp"
+ ),
# subtraction is not
(t.c.col1 - datetime.timedelta(seconds=30),
"(t.col1 - %(col1_1)s) :: timestamp"
@@ -104,6 +113,9 @@ class CompileTest(TestBase, AssertsCompiledSQL):
(t.c.col3 + datetime.timedelta(seconds=30),
"(t.col3 + %(col3_1)s) :: time"
),
+ (t.c.col6 + datetime.timedelta(seconds=30),
+ "(t.col6 + %(col6_1)s) :: time"
+ ),
(func.current_timestamp() - func.coalesce(t.c.col1, func.current_timestamp()),
"(CURRENT_TIMESTAMP - coalesce(t.col1, CURRENT_TIMESTAMP)) :: interval",
),