From 17d228f6268515bbf37fdd70a6ee3a62cb9a0b0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Duarte?= Date: Thu, 13 Jan 2022 17:20:06 -0500 Subject: Fixes(#7561) Add support for postgres.UUID literal_binds compilation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added string rendering to the :class:`.postgresql.UUID` datatype, so that stringifying a statement with "literal_binds" that uses this type will render an appropriate string value for the PostgreSQL backend. Pull request courtesy José Duarte. Fixes: #7561 Closes: #7563 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7563 Pull-request-sha: cf6fe73265342d7884a940c4b3a34c9552113ec3 Change-Id: I4b162bdcdce2293a90683e36da54e4a891a3c684 --- lib/sqlalchemy/dialects/postgresql/base.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/dialects/postgresql/base.py') diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index bf8812ae5..4f3e297ef 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1410,7 +1410,6 @@ from ...types import SMALLINT from ...types import TEXT from ...types import VARCHAR - IDX_USING = re.compile(r"^(?:btree|hash|gist|gin|[\w_]+)$", re.I) RESERVED_WORDS = set( @@ -1751,6 +1750,24 @@ class UUID(sqltypes.TypeEngine): else: return None + def literal_processor(self, dialect): + if self.as_uuid: + + def process(value): + if value is not None: + value = "'%s'::UUID" % value + return value + + return process + else: + + def process(value): + if value is not None: + value = "'%s'" % value + return value + + return process + PGUuid = UUID -- cgit v1.2.1