From: Mike Bayer Date: Tue, 29 Dec 2009 16:11:16 +0000 (+0000) Subject: make sure the native pg types work too X-Git-Tag: rel_0_5_8~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=17958b5b472e73dcf614f602b238106092157bcd;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git make sure the native pg types work too --- diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index 6605eebd97..51c7401fe5 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 a53dc64f5b..096a4b8e09 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", ),