]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Allow the value 0 for Postgresql TIME/TIMESTAMP precision
authorIonuț Ciocîrlan <jdxlark@gmail.com>
Wed, 23 Nov 2016 14:43:47 +0000 (09:43 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 23 Nov 2016 14:48:34 +0000 (09:48 -0500)
Change-Id: Ie38c48369222d95849645f027e2c659f503cfd53
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/322

doc/build/changelog/changelog_11.rst
lib/sqlalchemy/dialects/postgresql/base.py
test/dialect/postgresql/test_types.py

index 5ab661fdad947c0edeaa4adb8b0e65cfe97a87dd..a0aecf3679da8772a6fd5260a425d87a5e69f87a 100644 (file)
 .. 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
index 4c82325f566399bb58c5fad4dc68f2a06bafadc1..c5021249e71e5422b4f850da4fbc0418a7e647f3 100644 (file)
@@ -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"
         )
 
index a41d6db62a9691d98eb3126e46d80e8f91e207b9..b558d09fb1ccb3daf6473635a7ca594840f7a5de 100644 (file)
@@ -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)