idx1 = Index('test_idx1', tbl.c.data, postgresql_concurrently=True)
-The above index construct will render SQL as::
+The above index construct will render DDL for CREATE INDEX, assuming
+Postgresql 8.2 or higher is detected or for a connection-less dialect, as::
CREATE INDEX CONCURRENTLY test_idx1 ON testtbl (data)
-.. versionadded:: 0.9.9
+For DROP INDEX, assuming Postgresql 9.2 or higher is detected or for
+a connection-less dialect, it will emit::
+
+ DROP INDEX CONCURRENTLY test_idx1
+
+.. versionadded:: 1.1 support for CONCURRENTLY on DROP INDEX. The
+ CONCURRENTLY keyword is now only emitted if a high enough version
+ of Postgresql is detected on the connection (or for a connection-less
+ dialect).
+
.. _postgresql_index_reflection:
text += "UNIQUE "
text += "INDEX "
- concurrently = index.dialect_options['postgresql']['concurrently']
- if concurrently:
- text += "CONCURRENTLY "
+ if self.dialect._supports_create_index_concurrently:
+ concurrently = index.dialect_options['postgresql']['concurrently']
+ if concurrently:
+ text += "CONCURRENTLY "
text += "%s ON %s " % (
self._prepared_index_name(index,
text += " WHERE " + where_compiled
return text
+ def visit_drop_index(self, drop):
+ index = drop.element
+
+ text = "\nDROP INDEX "
+
+ if self.dialect._supports_drop_index_concurrently:
+ concurrently = index.dialect_options['postgresql']['concurrently']
+ if concurrently:
+ text += "CONCURRENTLY "
+
+ text += self._prepared_index_name(index, include_schema=True)
+ return text
+
def visit_exclude_constraint(self, constraint, **kw):
text = ""
if constraint.name is not None:
reflection_options = ('postgresql_ignore_search_path', )
_backslash_escapes = True
+ _supports_create_index_concurrently = True
+ _supports_drop_index_concurrently = True
def __init__(self, isolation_level=None, json_serializer=None,
json_deserializer=None, **kwargs):
"show standard_conforming_strings"
) == 'off'
+ self._supports_create_index_concurrently = \
+ self.server_version_info >= (8, 2)
+ self._supports_drop_index_concurrently = \
+ self.server_version_info >= (9, 2)
+
def on_connect(self):
if self.isolation_level is not None:
def connect(conn):
"CREATE INDEX CONCURRENTLY test_idx1 ON testtbl (data)"
)
+ dialect_8_1 = postgresql.dialect()
+ dialect_8_1._supports_create_index_concurrently = False
+ self.assert_compile(
+ schema.CreateIndex(idx1),
+ "CREATE INDEX test_idx1 ON testtbl (data)",
+ dialect=dialect_8_1
+ )
+
+ def test_drop_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.DropIndex(idx1),
+ "DROP INDEX CONCURRENTLY test_idx1"
+ )
+
+ dialect_9_1 = postgresql.dialect()
+ dialect_9_1._supports_drop_index_concurrently = False
+ self.assert_compile(
+ schema.DropIndex(idx1),
+ "DROP INDEX test_idx1",
+ dialect=dialect_9_1
+ )
+
def test_exclude_constraint_min(self):
m = MetaData()
tbl = Table('testtbl', m,