diff options
| author | Ionuț Ciocîrlan <jdxlark@gmail.com> | 2016-11-23 09:43:47 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-11-23 09:48:34 -0500 |
| commit | 868e98bf407175b016e9e5cbc95bcf0cc859362a (patch) | |
| tree | b233d94a46691704051834716f342b26b67fd9d1 | |
| parent | df9b6492e5ca47e26d539d2283fa816a2d5c8ad6 (diff) | |
| download | sqlalchemy-868e98bf407175b016e9e5cbc95bcf0cc859362a.tar.gz | |
Allow the value 0 for Postgresql TIME/TIMESTAMP precision
Change-Id: Ie38c48369222d95849645f027e2c659f503cfd53
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/322
| -rw-r--r-- | doc/build/changelog/changelog_11.rst | 7 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 8 | ||||
| -rw-r--r-- | test/dialect/postgresql/test_types.py | 4 |
3 files changed, 15 insertions, 4 deletions
diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst index 5ab661fda..a0aecf367 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 4c82325f5..c5021249e 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 a41d6db62..b558d09fb 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) |
