From: Malik Diarra Date: Sat, 16 Aug 2014 23:39:14 +0000 (+0200) Subject: quoting tablespace name in create table command in postgresql dialect X-Git-Tag: rel_1_0_0b1~205^2~49^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8e03430acdb98d7e5fef4a48a3120b928ed3266d;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git quoting tablespace name in create table command in postgresql dialect --- diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 9b30bf8949..b09eaba725 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1459,7 +1459,8 @@ class PGDDLCompiler(compiler.DDLCompiler): on_commit_options = table.dialect_options['postgresql']['on_commit'].replace("_", " ").upper() table_opts.append('ON COMMIT %s' % on_commit_options) if table.dialect_options['postgresql']['tablespace']: - table_opts.append('TABLESPACE %s' % table.dialect_options['postgresql']['tablespace']) + tablespace_name = table.dialect_options['postgresql']['tablespace'] + table_opts.append('TABLESPACE %s' % self.preparer.quote(tablespace_name)) return ' '.join(table_opts) diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index b439ab916f..e4a8c02eb0 100644 --- a/test/dialect/postgresql/test_compiler.py +++ b/test/dialect/postgresql/test_compiler.py @@ -172,6 +172,11 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile(schema.CreateTable(tbl), "CREATE TABLE atable (id INTEGER)TABLESPACE sometablespace") + # testing quoting of tablespace name + tbl = Table('anothertable', m, Column("id", Integer), postgresql_tablespace = 'table') + self.assert_compile(schema.CreateTable(tbl), + 'CREATE TABLE anothertable (id INTEGER)TABLESPACE "table"') + def test_create_table_with_oids(self): m = MetaData() tbl = Table('atable', m, Column("id", Integer), postgresql_withoids = True, )