]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug where CREATE TABLE with a no-column table, but a constraint
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 2 Dec 2015 00:03:03 +0000 (19:03 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 2 Dec 2015 00:04:48 +0000 (19:04 -0500)
such as a CHECK constraint would render an erroneous comma in the
definition; this scenario can occur such as with a Postgresql
INHERITS table that has no columns of its own.
fixes #3598

(cherry picked from commit 9695faf32981406b12a6468b98d5c9b673f8e219)

doc/build/changelog/changelog_10.rst
lib/sqlalchemy/sql/compiler.py
test/sql/test_compiler.py

index 5b66baf97eed44d3a11ac77faadf452d1e2efbaa..ffc2c344682c13917952a0ae6c1c8a7b1a451b9c 100644 (file)
 .. changelog::
     :version: 1.0.10
 
+    .. change::
+        :tags: bug, sql, postgresql
+        :tickets: 3598
+        :versions: 1.1.0b1
+
+        Fixed bug where CREATE TABLE with a no-column table, but a constraint
+        such as a CHECK constraint would render an erroneous comma in the
+        definition; this scenario can occur such as with a Postgresql
+        INHERITS table that has no columns of its own.
+
     .. change::
         :tags: bug, mssql
         :tickets: 3585
index da45a93f390b1adf5b15f01328b965a08c4db3d7..996849c5fe154e067cc73c81cb9a47a6d29816a9 100644 (file)
@@ -2168,7 +2168,7 @@ class DDLCompiler(Compiled):
             table, _include_foreign_key_constraints=
             create.include_foreign_key_constraints)
         if const:
-            text += ", \n\t" + const
+            text += separator + "\t" + const
 
         text += "\n)%s\n\n" % self.post_create_table(table)
         return text
index 06cb80ba0f46ef627e17fea6ef5dab14655c4b8e..4250c7b1233b23f20f52c38f12789012e9a71853 100644 (file)
@@ -18,7 +18,7 @@ from sqlalchemy import Integer, String, MetaData, Table, Column, select, \
     literal, and_, null, type_coerce, alias, or_, literal_column,\
     Float, TIMESTAMP, Numeric, Date, Text, union, except_,\
     intersect, union_all, Boolean, distinct, join, outerjoin, asc, desc,\
-    over, subquery, case, true
+    over, subquery, case, true, CheckConstraint
 import decimal
 from sqlalchemy.util import u
 from sqlalchemy import exc, sql, util, types, schema
@@ -2857,6 +2857,30 @@ class DDLTest(fixtures.TestBase, AssertsCompiledSQL):
             "CREATE TABLE t (x INTEGER, z INTEGER)"
         )
 
+    def test_table_no_cols(self):
+        m = MetaData()
+        t1 = Table('t1', m)
+        self.assert_compile(
+            schema.CreateTable(t1),
+            "CREATE TABLE t1 ()"
+        )
+
+    def test_table_no_cols_w_constraint(self):
+        m = MetaData()
+        t1 = Table('t1', m, CheckConstraint('a = 1'))
+        self.assert_compile(
+            schema.CreateTable(t1),
+            "CREATE TABLE t1 (CHECK (a = 1))"
+        )
+
+    def test_table_one_col_w_constraint(self):
+        m = MetaData()
+        t1 = Table('t1', m, Column('q', Integer), CheckConstraint('a = 1'))
+        self.assert_compile(
+            schema.CreateTable(t1),
+            "CREATE TABLE t1 (q INTEGER, CHECK (a = 1))"
+        )
+
 
 class InlineDefaultTest(fixtures.TestBase, AssertsCompiledSQL):
     __dialect__ = 'default'