]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- document how to use autocommit isolation level for CONCURRENTLY,
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 12 Jan 2017 20:57:46 +0000 (15:57 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 12 Jan 2017 20:58:51 +0000 (15:58 -0500)
fixes #3887

Change-Id: I6d1a13b7bb4169204105c7a100d17cfed3ded9d1
(cherry picked from commit 0460bc79d9986132646049d8167bd5dbe3388a65)

lib/sqlalchemy/dialects/postgresql/base.py

index 9d596dfd3289f11909080ddfaf932efb26dca9bf..d0aa318dba76cb28bb23b1fa7d76b5c5cea7471a 100644 (file)
@@ -431,6 +431,26 @@ The above index construct will render SQL as::
 
 .. versionadded:: 0.9.9
 
+When using CONCURRENTLY, the Postgresql database requires that the statement
+be invoked outside of a transaction block.   The Python DBAPI enforces that
+even for a single statement, a transaction is present, so to use this
+construct, the DBAPI's "autocommit" mode must be used::
+
+    metadata = MetaData()
+    table = Table(
+        "foo", metadata,
+        Column("id", String))
+    index = Index(
+        "foo_idx", table.c.id, postgresql_concurrently=True)
+
+    with engine.connect() as conn:
+        with conn.execution_options(isolation_level='AUTOCOMMIT'):
+            table.create(conn)
+
+.. seealso::
+
+    :ref:`postgresql_isolation_level`
+
 .. _postgresql_index_reflection:
 
 Postgresql Index Reflection