]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
merge r6591, r6592 from 0.5 branch for PGInterval etc. /extract
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 29 Dec 2009 16:19:09 +0000 (16:19 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 29 Dec 2009 16:19:09 +0000 (16:19 +0000)
lib/sqlalchemy/dialects/postgresql/base.py
lib/sqlalchemy/sql/util.py
test/dialect/test_postgresql.py

index a71984be4ccd4104e3cc2721fbc69fac772d6070..1d7240fbfe0d75c8eb97339410c2fe1bddf57dbc 100644 (file)
@@ -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
 
index 7bcc8e7d74ab69fcddf94b986fbfdb19c5d2ae6d..1b4bc67fcc36c1ef6fdee2f84b521de947b66f8c 100644 (file)
@@ -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__))
index 7cf22a3edc08d821d10a2ed69bef3c561f261f41..fdc2e7ea926df12bc073af158467bae3e360b508 100644 (file)
@@ -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),