summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py4
-rw-r--r--lib/sqlalchemy/sql/util.py3
-rw-r--r--test/dialect/test_postgresql.py11
3 files changed, 16 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index a71984be4..1d7240fbf 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -110,6 +110,10 @@ class INTERVAL(sqltypes.TypeEngine):
def adapt(self, impltype):
return impltype(self.precision)
+
+ @property
+ def _type_affinity(self):
+ return sqltypes.Interval
PGInterval = INTERVAL
diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py
index 7bcc8e7d7..1b4bc67fc 100644
--- a/lib/sqlalchemy/sql/util.py
+++ b/lib/sqlalchemy/sql/util.py
@@ -104,6 +104,9 @@ def determine_date_affinity(expr):
left_affin, right_affin = \
determine_date_affinity(expr.left), \
determine_date_affinity(expr.right)
+
+ if left_affin is None or right_affin is None:
+ return None
if operators.is_commutative(expr.operator):
key = tuple(sorted([left_affin, right_affin], key=lambda cls:cls.__name__))
diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py
index 7cf22a3ed..fdc2e7ea9 100644
--- a/test/dialect/test_postgresql.py
+++ b/test/dialect/test_postgresql.py
@@ -100,8 +100,9 @@ class CompileTest(TestBase, AssertsCompiledSQL):
"CREATE INDEX test_idx1 ON testtbl (data) WHERE data > 5 AND data < 10", dialect=postgresql.dialect())
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', postgresql.INTERVAL)
+ )
for field in 'year', 'month', 'day', 'epoch', 'hour':
for expr, compiled_expr in [
@@ -130,6 +131,9 @@ class CompileTest(TestBase, AssertsCompiledSQL):
(datetime.timedelta(days=5) + t.c.col2,
"(%(col2_1)s + t.col2) :: timestamp"
),
+ (t.c.col1 + t.c.col4,
+ "(t.col1 + t.col4) :: timestamp"
+ ),
# subtraction is not
(t.c.col1 - datetime.timedelta(seconds=30),
"(t.col1 - %(col1_1)s) :: timestamp"
@@ -152,6 +156,9 @@ class CompileTest(TestBase, AssertsCompiledSQL):
(literal(datetime.timedelta(seconds=10)) - literal(datetime.timedelta(seconds=10)),
"(%(param_1)s - %(param_2)s) :: interval"
),
+ (t.c.col3 + "some string", # dont crack up on entirely unsupported types
+ "t.col3 + %(col3_1)s"
+ )
]:
self.assert_compile(
select([extract(field, expr)]).select_from(t),