]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
quoting tablespace name in create table command in postgresql dialect
authorMalik Diarra <malik.diarra@gmail.com>
Sat, 16 Aug 2014 23:39:14 +0000 (01:39 +0200)
committerMalik Diarra <malik.diarra@gmail.com>
Sat, 16 Aug 2014 23:56:02 +0000 (01:56 +0200)
lib/sqlalchemy/dialects/postgresql/base.py
test/dialect/postgresql/test_compiler.py

index 9b30bf8949c0289e94b5c820cf484aea70199a14..b09eaba725b7171429789695edc2fd2ab1ef2c44 100644 (file)
@@ -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)
 
index b439ab916fc325c6f27d325ed6e3210a62bea40c..e4a8c02eb0c3cf3dfd75a10199c139d3e4bfbb76 100644 (file)
@@ -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, )