diff options
| author | Iuri de Silvio <iurisilvio@gmail.com> | 2015-02-25 21:05:31 -0300 |
|---|---|---|
| committer | Iuri de Silvio <iurisilvio@gmail.com> | 2015-02-25 21:05:31 -0300 |
| commit | 955576fcf6e7aff7fe924ec3b33bb6d243ddd312 (patch) | |
| tree | 32690318970204b1b1a7fc36ba33d772a6129512 | |
| parent | c5edbc6fdc611d3c812735d83fe056fbb7d113f5 (diff) | |
| download | sqlalchemy-955576fcf6e7aff7fe924ec3b33bb6d243ddd312.tar.gz | |
Dialect option `postgresql_concurrently` to `Index` construct.
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 11 | ||||
| -rw-r--r-- | test/dialect/postgresql/test_compiler.py | 10 |
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 1935d0cad..c819f36c3 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1459,7 +1459,13 @@ class PGDDLCompiler(compiler.DDLCompiler): text = "CREATE " if index.unique: text += "UNIQUE " - text += "INDEX %s ON %s " % ( + text += "INDEX " + + concurrently = index.dialect_options['postgresql']['concurrently'] + if concurrently: + text += "CONCURRENTLY " + + text += "%s ON %s " % ( self._prepared_index_name(index, include_schema=False), preparer.format_table(index.table) @@ -1812,7 +1818,8 @@ class PGDialect(default.DefaultDialect): (schema.Index, { "using": False, "where": None, - "ops": {} + "ops": {}, + "concurrently": False, }), (schema.Table, { "ignore_search_path": False, diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index 5717df9f7..aa3f80fdc 100644 --- a/test/dialect/postgresql/test_compiler.py +++ b/test/dialect/postgresql/test_compiler.py @@ -389,6 +389,16 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): "CREATE INDEX test_idx1 ON testtbl ((data + 5))" ) + def test_create_index_concurrently(self): + m = MetaData() + tbl = Table('testtbl', m, Column('data', Integer)) + + idx1 = Index('test_idx1', tbl.c.data, postgresql_concurrently=True) + self.assert_compile( + schema.CreateIndex(idx1), + "CREATE INDEX CONCURRENTLY test_idx1 ON testtbl (data)" + ) + def test_exclude_constraint_min(self): m = MetaData() tbl = Table('testtbl', m, |
