summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Hayes <jacob.r.hayes@gmail.com>2017-12-15 09:56:59 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2017-12-18 11:33:09 -0500
commit756d5782870029f2d97b1aa171abd61dbf4cbcb4 (patch)
tree3dac92daa83fd7e2dcdacb858e43d0fef4e547ec
parent19e13cf3d203b59ad285ab0193cb9fc53c4fcff2 (diff)
downloadsqlalchemy-756d5782870029f2d97b1aa171abd61dbf4cbcb4.tar.gz
Add TRUNCATE to postgres autocommit regexp
Extends AUTOCOMMIT_REGEXP for the postgres dialect to include `TRUNCATE`. Change-Id: I315e03674b89bb89aae669b8655481e4d890491e Pull-request: https://github.com/zzzeek/sqlalchemy/pull/407
-rw-r--r--doc/build/changelog/unreleased_11/pg_truncate.rst6
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py2
-rw-r--r--test/dialect/postgresql/test_dialect.py3
3 files changed, 10 insertions, 1 deletions
diff --git a/doc/build/changelog/unreleased_11/pg_truncate.rst b/doc/build/changelog/unreleased_11/pg_truncate.rst
new file mode 100644
index 000000000..4720c288f
--- /dev/null
+++ b/doc/build/changelog/unreleased_11/pg_truncate.rst
@@ -0,0 +1,6 @@
+.. change::
+ :tags: bug, postgresql
+
+ Added "TRUNCATE" to the list of keywords accepted by the
+ Postgresql dialect as an "autocommit"-triggering keyword.
+ Pull request courtesy Jacob Hayes.
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index 043efd6df..f11604259 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -925,7 +925,7 @@ from sqlalchemy.types import INTEGER, BIGINT, SMALLINT, VARCHAR, \
AUTOCOMMIT_REGEXP = re.compile(
r'\s*(?:UPDATE|INSERT|CREATE|DELETE|DROP|ALTER|GRANT|REVOKE|'
- 'IMPORT FOREIGN SCHEMA|REFRESH MATERIALIZED VIEW)',
+ 'IMPORT FOREIGN SCHEMA|REFRESH MATERIALIZED VIEW|TRUNCATE)',
re.I | re.UNICODE)
RESERVED_WORDS = set(
diff --git a/test/dialect/postgresql/test_dialect.py b/test/dialect/postgresql/test_dialect.py
index 29aa62e3f..3db7fef48 100644
--- a/test/dialect/postgresql/test_dialect.py
+++ b/test/dialect/postgresql/test_dialect.py
@@ -418,3 +418,6 @@ class AutocommitTextTest(test_execute.AutocommitTextTest):
def test_revoke(self):
self._test_keyword("REVOKE USAGE ON SCHEMA fooschema FROM foorole")
+
+ def test_truncate(self):
+ self._test_keyword("TRUNCATE footable")