From 756d5782870029f2d97b1aa171abd61dbf4cbcb4 Mon Sep 17 00:00:00 2001 From: Jacob Hayes Date: Fri, 15 Dec 2017 09:56:59 -0500 Subject: [PATCH] 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 --- doc/build/changelog/unreleased_11/pg_truncate.rst | 6 ++++++ lib/sqlalchemy/dialects/postgresql/base.py | 2 +- test/dialect/postgresql/test_dialect.py | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 doc/build/changelog/unreleased_11/pg_truncate.rst 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 0000000000..4720c288f8 --- /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 043efd6df5..f116042591 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 29aa62e3fe..3db7fef48b 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") -- 2.47.3