From: Mike Bayer Date: Wed, 27 Feb 2008 20:23:23 +0000 (+0000) Subject: - postgres TIMESTAMP renders correctly [ticket:981] X-Git-Tag: rel_0_4_4~53 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9302f2b2fbae513c675e5fcd19e3836d4b63d0fe;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - postgres TIMESTAMP renders correctly [ticket:981] --- diff --git a/CHANGES b/CHANGES index 460244b05b..c2bd34e8aa 100644 --- a/CHANGES +++ b/CHANGES @@ -62,6 +62,7 @@ CHANGES - dialects - Invalid SQLite connection URLs now raise an error. + - postgres TIMESTAMP renders correctly [ticket:981] 0.4.3 ------ diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index a9fa90c688..9f8e986071 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -631,6 +631,13 @@ class PGCompiler(compiler.DefaultCompiler): } ) + functions = compiler.DefaultCompiler.functions.copy() + functions.update ( + { + 'TIMESTAMP':lambda x:'TIMESTAMP %s' % x, + } + ) + def visit_sequence(self, seq): if seq.optional: return None diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index c5ff974e52..8a2a5f2ddb 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -349,7 +349,7 @@ class DefaultCompiler(engine.Compiled): name = self.function_string(func) if callable(name): - return name(*[self.process(x) for x in func.clause_expr]) + return name(*[self.process(x) for x in func.clauses]) else: return ".".join(func.packagenames + [name]) % {'expr':self.function_argspec(func)} @@ -357,7 +357,7 @@ class DefaultCompiler(engine.Compiled): return self.process(func.clause_expr) def function_string(self, func): - return self.functions.get(func.__class__, func.name + "%(expr)s") + return self.functions.get(func.__class__, self.functions.get(func.name, func.name + "%(expr)s")) def visit_compound_select(self, cs, asfrom=False, parens=True, **kwargs): stack_entry = {'select':cs} diff --git a/test/dialect/postgres.py b/test/dialect/postgres.py index 9ec44203a4..71fb0c763f 100644 --- a/test/dialect/postgres.py +++ b/test/dialect/postgres.py @@ -705,5 +705,15 @@ class ArrayTest(TestBase, AssertsExecutionResults): self.assertEquals(results[1]['strarr'], [[u'm\xe4\xe4'], [u'm\xf6\xf6']]) arrtable.delete().execute() +class TimeStampTest(TestBase, AssertsExecutionResults): + __only_on__ = 'postgres' + def test_timestamp(self): + engine = testing.db + connection = engine.connect() + s = select([func.TIMESTAMP("12/25/07").label("ts")]) + result = connection.execute(s).fetchone() + self.assertEqual(result[0], datetime.datetime(2007, 12, 25, 0, 0)) + + if __name__ == "__main__": testenv.main()