From: Malik Diarra Date: Tue, 12 Aug 2014 23:39:09 +0000 (+0200) Subject: Adding a tablespace options for postgresql create table X-Git-Tag: rel_1_0_0b1~205^2~49^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ef6042ff461e490c2a3040f18f0a3688b2e601a0;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Adding a tablespace options for postgresql create table --- diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index c2b1d66f43..0f008642e8 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -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 }) ] diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index b08fb01603..301f80fd44 100644 --- a/test/dialect/postgresql/test_compiler.py +++ b/test/dialect/postgresql/test_compiler.py @@ -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))