diff options
| -rw-r--r-- | doc/build/changelog/changelog_11.rst | 10 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 8 | ||||
| -rw-r--r-- | test/dialect/postgresql/test_dialect.py | 11 |
3 files changed, 29 insertions, 0 deletions
diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst index 7a462eb08..681672b50 100644 --- a/doc/build/changelog/changelog_11.rst +++ b/doc/build/changelog/changelog_11.rst @@ -21,6 +21,16 @@ .. changelog:: :version: 1.1.6 + .. change:: 3804 + :tags: bug, postgresql + :tickets: 3804 + + 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. + .. change:: 3909 :tags: bug, orm :tickets: 3909 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' diff --git a/test/dialect/postgresql/test_dialect.py b/test/dialect/postgresql/test_dialect.py index ba68faf16..a9ef09dbd 100644 --- a/test/dialect/postgresql/test_dialect.py +++ b/test/dialect/postgresql/test_dialect.py @@ -18,6 +18,7 @@ from sqlalchemy.engine import engine_from_config from sqlalchemy.engine import url from sqlalchemy.testing import is_ from sqlalchemy.testing import expect_deprecated +from ...engine import test_execute class MiscTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): @@ -295,3 +296,13 @@ class MiscTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): ddl_compiler.get_column_specification(t.c.c), "c %s NOT NULL" % expected ) + + +class AutocommitTextTest(test_execute.AutocommitTextTest): + __only_on__ = 'postgresql' + + def test_import_foreign_schema(self): + self._test_keyword("IMPORT FOREIGN SCHEMA foob") + + def test_refresh_view(self): + self._test_keyword("REFRESH MATERIALIZED VIEW fooview") |
