From 5565afeac20ea3612c3f427f58efacd8487ac159 Mon Sep 17 00:00:00 2001 From: Matt del Valle Date: Mon, 13 Mar 2023 19:07:37 +0100 Subject: [PATCH] Add documentation + pass connection through to PGDialect._set_backslash_escapes() --- doc/build/changelog/unreleased_20/9442.rst | 7 +++++++ lib/sqlalchemy/dialects/postgresql/base.py | 18 +++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 doc/build/changelog/unreleased_20/9442.rst diff --git a/doc/build/changelog/unreleased_20/9442.rst b/doc/build/changelog/unreleased_20/9442.rst new file mode 100644 index 0000000000..2b172195c6 --- /dev/null +++ b/doc/build/changelog/unreleased_20/9442.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: usecase, postgresql + :tickets: 9442 + + Modifications to the base PostgreSQL dialect to allow for better integration with the + sqlalchemy-redshift third party dialect for SQLAlchemy 2.0. Pull request courtesy + matthewgdv. diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 580897f8a1..3c1fc00734 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -3030,7 +3030,7 @@ class PGDialect(default.DefaultDialect): # https://www.postgresql.org/docs/9.3/static/release-9-2.html#AEN116689 self.supports_smallserial = self.server_version_info >= (9, 2) - self.set_backslash_escapes() + self._set_backslash_escapes(connection) self._supports_drop_index_concurrently = self.server_version_info >= ( 9, @@ -3038,14 +3038,6 @@ class PGDialect(default.DefaultDialect): ) self.supports_identity_columns = self.server_version_info >= (10,) - def set_backslash_escapes(self): - # this method is provided as an override hook for descendant - # dialects (e.g. Redshift), so removing it may break them - std_string = connection.exec_driver_sql( - "show standard_conforming_strings" - ).scalar() - self._backslash_escapes = std_string == "off" - def get_isolation_level_values(self, dbapi_conn): # note the generic dialect doesn't have AUTOCOMMIT, however # all postgresql dialects should include AUTOCOMMIT. @@ -4704,3 +4696,11 @@ class PGDialect(default.DefaultDialect): domains.append(domain_rec) return domains + + def _set_backslash_escapes(self, connection): + # this method is provided as an override hook for descendant + # dialects (e.g. Redshift), so removing it may break them + std_string = connection.exec_driver_sql( + "show standard_conforming_strings" + ).scalar() + self._backslash_escapes = std_string == "off" -- 2.47.3