diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-02-13 14:20:38 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-02-13 14:45:40 -0500 |
commit | 3b6004e6ab3fef8e37fb42981c02f4dfa34fe3b7 (patch) | |
tree | 1b259c32e5b425ad0373f6d24e9b4fa2b7d415d2 /lib/sqlalchemy/dialects/postgresql/base.py | |
parent | f107dd78eccb9a6d38d84364d9efd6ad5e1c71da (diff) | |
download | sqlalchemy-3b6004e6ab3fef8e37fb42981c02f4dfa34fe3b7.tar.gz |
Add new DDL autocommit expressions for Postgresql
Added regular expressions for the "IMPORT FOREIGN SCHEMA",
"REFRESH MATERIALIZED VIEW" Postgresql statements so that they
autocommit when invoked via a connection or engine without
an explicit transaction. Pull requests courtesy Frazer McLean
and Paweł Stiasny.
Fixes: #3840
Co-authored-by: Frazer McLean
Co-authored-by: Paweł Stiasny
Change-Id: I92b2b61683d29d57fa23a66a3559120cb1241c2f
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/323
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index fd25058a2..aaaa64cf1 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -878,6 +878,11 @@ from sqlalchemy.types import INTEGER, BIGINT, SMALLINT, VARCHAR, \ CHAR, TEXT, FLOAT, NUMERIC, \ DATE, BOOLEAN, REAL +AUTOCOMMIT_REGEXP = re.compile( + r'\s*(?:UPDATE|INSERT|CREATE|DELETE|DROP|ALTER|' + 'IMPORT FOREIGN SCHEMA|REFRESH MATERIALIZED VIEW)', + re.I | re.UNICODE) + RESERVED_WORDS = set( ["all", "analyse", "analyze", "and", "any", "array", "as", "asc", "asymmetric", "both", "case", "cast", "check", "collate", "column", @@ -1998,6 +2003,9 @@ class PGExecutionContext(default.DefaultExecutionContext): return super(PGExecutionContext, self).get_insert_default(column) + def should_autocommit_text(self, statement): + return AUTOCOMMIT_REGEXP.match(statement) + class PGDialect(default.DefaultDialect): name = 'postgresql' |