]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
make sure the native pg types work too
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 29 Dec 2009 16:11:16 +0000 (16:11 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 29 Dec 2009 16:11:16 +0000 (16:11 +0000)
lib/sqlalchemy/databases/postgres.py
test/dialect/test_postgres.py

index 6605eebd97e623a12d158b0978d594825ee66bcb..51c7401fe58396ce126a98404e438aa78db84c8a 100644 (file)
@@ -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"
index a53dc64f5bb98cffabb97fddddcd639d2ac085c4..096a4b8e095a7011f112c9052af2e708641966be 100644 (file)
@@ -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",
                 ),