]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Adding a tablespace options for postgresql create table
authorMalik Diarra <malik.diarra@gmail.com>
Tue, 12 Aug 2014 23:39:09 +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 c2b1d66f43b42e8e39dc8869147861d0b17e0400..0f008642e8294aa8fd86ccb089b998d707e9d75c 100644 (file)
@@ -1448,6 +1448,13 @@ class PGDDLCompiler(compiler.DDLCompiler):
         text += self.define_constraint_deferrability(constraint)
         return text
 
+    def post_create_table(self, table):
+        table_opts = []
+        if table.dialect_options['postgresql']['tablespace']:
+            table_opts.append('TABLESPACE %s' % table.dialect_options['postgresql']['tablespace'])
+
+        return ' '.join(table_opts)
+
 
 class PGTypeCompiler(compiler.GenericTypeCompiler):
 
@@ -1707,7 +1714,8 @@ class PGDialect(default.DefaultDialect):
             "ops": {}
         }),
         (schema.Table, {
-            "ignore_search_path": False
+            "ignore_search_path": False,
+            "tablespace": None
         })
     ]
 
index b08fb016038b51383ceabd44fcd8e4fec5ef32c2..301f80fd4408a261e70a428e4704a6702a5e91b9 100644 (file)
@@ -166,6 +166,12 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
                             "VARCHAR(1), CHECK (somecolumn IN ('x', "
                             "'y', 'z')))")
 
+    def test_create_table_with_tablespace(self):
+        m = MetaData()
+        tbl = Table('atable', m, Column("id", Integer), postgresql_tablespace = 'sometablespace')
+        self.assert_compile(schema.CreateTable(tbl),
+                "CREATE TABLE atable (id INTEGER)TABLESPACE sometablespace")
+
     def test_create_partial_index(self):
         m = MetaData()
         tbl = Table('testtbl', m, Column('data', Integer))