diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-12-01 19:03:03 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-12-01 19:03:03 -0500 |
commit | 9695faf32981406b12a6468b98d5c9b673f8e219 (patch) | |
tree | 1d3721494ae2692fdd3e4ef5b93b532ae56710b3 | |
parent | ab6946769742602e40fb9ed9dde5f642885d1906 (diff) | |
download | sqlalchemy-9695faf32981406b12a6468b98d5c9b673f8e219.tar.gz |
- 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.
fixes #3598
-rw-r--r-- | doc/build/changelog/changelog_10.rst | 10 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 2 | ||||
-rw-r--r-- | test/sql/test_compiler.py | 26 |
3 files changed, 36 insertions, 2 deletions
diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst index 5b66baf97..ffc2c3446 100644 --- a/doc/build/changelog/changelog_10.rst +++ b/doc/build/changelog/changelog_10.rst @@ -19,6 +19,16 @@ :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 :versions: 1.1.0b1 diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index d28ac313b..6766c99b7 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -2163,7 +2163,7 @@ class DDLCompiler(Compiled): table, _include_foreign_key_constraints= # noqa 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 diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index f6f2ec740..ffd13309b 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -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 @@ -2931,6 +2931,30 @@ class DDLTest(fixtures.TestBase, AssertsCompiledSQL): "PRIMARY KEY (b, a))" ) + 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' |