From: Ionuț Ciocîrlan Date: Wed, 23 Nov 2016 14:43:47 +0000 (-0500) Subject: Allow the value 0 for Postgresql TIME/TIMESTAMP precision X-Git-Tag: rel_1_1_5~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=868e98bf407175b016e9e5cbc95bcf0cc859362a;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Allow the value 0 for Postgresql TIME/TIMESTAMP precision Change-Id: Ie38c48369222d95849645f027e2c659f503cfd53 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/322 --- diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst index 5ab661fdad..a0aecf3679 100644 --- a/doc/build/changelog/changelog_11.rst +++ b/doc/build/changelog/changelog_11.rst @@ -21,6 +21,13 @@ .. changelog:: :version: 1.1.5 + .. change:: pg_timestamp_zero_prec + :tags: bug, postgresql + + The :class:`.postgresql.TIME` and :class:`.postgresql.TIMESTAMP` + datatypes now support a setting of zero for "precision"; previously + a zero would be ignored. Pull request courtesy Ionuț Ciocîrlan. + .. change:: 3859 :tags: bug, sql :tickets: 3859 diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 4c82325f56..c5021249e7 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1730,15 +1730,15 @@ class PGTypeCompiler(compiler.GenericTypeCompiler): def visit_TIMESTAMP(self, type_, **kw): return "TIMESTAMP%s %s" % ( - getattr(type_, 'precision', None) and "(%d)" % - type_.precision or "", + "(%d)" % type_.precision + if getattr(type_, 'precision', None) is not None else "", (type_.timezone and "WITH" or "WITHOUT") + " TIME ZONE" ) def visit_TIME(self, type_, **kw): return "TIME%s %s" % ( - getattr(type_, 'precision', None) and "(%d)" % - type_.precision or "", + "(%d)" % type_.precision + if getattr(type_, 'precision', None) is not None else "", (type_.timezone and "WITH" or "WITHOUT") + " TIME ZONE" ) diff --git a/test/dialect/postgresql/test_types.py b/test/dialect/postgresql/test_types.py index a41d6db62a..b558d09fb1 100644 --- a/test/dialect/postgresql/test_types.py +++ b/test/dialect/postgresql/test_types.py @@ -697,6 +697,10 @@ class TimePrecisionTest(fixtures.TestBase, AssertsCompiledSQL): 'TIMESTAMP(5) WITHOUT TIME ZONE'), (postgresql.TIMESTAMP(timezone=True, precision=5), 'TIMESTAMP(5) WITH TIME ZONE'), + (postgresql.TIME(precision=0), + 'TIME(0) WITHOUT TIME ZONE'), + (postgresql.TIMESTAMP(precision=0), + 'TIMESTAMP(0) WITHOUT TIME ZONE'), ]: self.assert_compile(type_, expected)