From: Jacob Hayes Date: Fri, 15 Dec 2017 14:56:59 +0000 (-0500) Subject: Add TRUNCATE to postgres autocommit regexp X-Git-Tag: rel_1_1_16~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe84543cc78027d7c60b627d27164cdbb90cf622;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git 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 (cherry picked from commit 756d5782870029f2d97b1aa171abd61dbf4cbcb4) --- 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 e5f164d573..627a62f9af 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 5ab17ea8cd..446765872e 100644 --- a/test/dialect/postgresql/test_dialect.py +++ b/test/dialect/postgresql/test_dialect.py @@ -322,3 +322,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")