From dfa1d3b28f1a0abf1e11c76a94f7a65bf98d29af Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Wed, 10 Mar 2021 23:54:52 +0100 Subject: CAST the elements in ARRAYs when using psycopg2 Adjusted the psycopg2 dialect to emit an explicit PostgreSQL-style cast for bound parameters that contain ARRAY elements. This allows the full range of datatypes to function correctly within arrays. The asyncpg dialect already generated these internal casts in the final statement. This also includes support for array slice updates as well as the PostgreSQL-specific :meth:`_postgresql.ARRAY.contains` method. Fixes: #6023 Change-Id: Ia7519ac4371a635f05ac69a3a4d0f4e6d2f04cad --- lib/sqlalchemy/dialects/postgresql/array.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'lib/sqlalchemy/dialects/postgresql/array.py') diff --git a/lib/sqlalchemy/dialects/postgresql/array.py b/lib/sqlalchemy/dialects/postgresql/array.py index 91bb89ea9..c2d99845f 100644 --- a/lib/sqlalchemy/dialects/postgresql/array.py +++ b/lib/sqlalchemy/dialects/postgresql/array.py @@ -330,12 +330,6 @@ class ARRAY(sqltypes.ARRAY): for x in arr ) - @util.memoized_property - def _require_cast(self): - return self._against_native_enum or isinstance( - self.item_type, sqltypes.JSON - ) - @util.memoized_property def _against_native_enum(self): return ( @@ -344,10 +338,7 @@ class ARRAY(sqltypes.ARRAY): ) def bind_expression(self, bindvalue): - if self._require_cast: - return expression.cast(bindvalue, self) - else: - return bindvalue + return bindvalue def bind_processor(self, dialect): item_proc = self.item_type.dialect_impl(dialect).bind_processor( -- cgit v1.2.1