summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/elements.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/sql/elements.py')
-rw-r--r--lib/sqlalchemy/sql/elements.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py
index 69e365bd3..91ce0a090 100644
--- a/lib/sqlalchemy/sql/elements.py
+++ b/lib/sqlalchemy/sql/elements.py
@@ -1753,7 +1753,10 @@ class Cast(ColumnElement):
"""
self.type = type_api.to_instance(totype)
self.clause = _literal_as_binds(clause, None)
- if isinstance(self.clause, BindParameter) and self.clause.type._isnull:
+ if isinstance(self.clause, BindParameter) and (
+ self.clause.type._isnull
+ or self.clause.type._type_affinity is self.type._type_affinity
+ ):
self.clause = self.clause._clone()
self.clause.type = self.type