summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/coercions.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-04-28 18:31:51 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-04-29 14:43:09 -0400
commitaba308868544b21bafa0b3435701ddc908654b0a (patch)
tree9160bdeacf66b4227e73203f7bb81a074d463927 /lib/sqlalchemy/sql/coercions.py
parent5b12393e81f6b8953e9ebd46801e6943007b7a56 (diff)
downloadsqlalchemy-aba308868544b21bafa0b3435701ddc908654b0a.tar.gz
Use non-subquery form for empty IN
Revised the "EMPTY IN" expression to no longer rely upon using a subquery, as this was causing some compatibility and performance problems. The new approach for selected databases takes advantage of using a NULL-returning IN expression combined with the usual "1 != 1" or "1 = 1" expression appended by AND or OR. The expression is now the default for all backends other than SQLite, which still had some compatibility issues regarding tuple "IN" for older SQLite versions. Third party dialects can still override how the "empty set" expression renders by implementing a new compiler method ``def visit_empty_set_op_expr(self, type_, expand_op)``, which takes precedence over the existing ``def visit_empty_set_expr(self, element_types)`` which remains in place. Fixes: #6258 Fixes: #6397 Change-Id: I2df09eb00d2ad3b57039ae48128fdf94641b5e59
Diffstat (limited to 'lib/sqlalchemy/sql/coercions.py')
-rw-r--r--lib/sqlalchemy/sql/coercions.py11
1 files changed, 3 insertions, 8 deletions
diff --git a/lib/sqlalchemy/sql/coercions.py b/lib/sqlalchemy/sql/coercions.py
index b7aba9d74..820fc1bf1 100644
--- a/lib/sqlalchemy/sql/coercions.py
+++ b/lib/sqlalchemy/sql/coercions.py
@@ -561,14 +561,9 @@ class InElementImpl(RoleImpl):
return element.self_group(against=operator)
elif isinstance(element, elements.BindParameter):
- if not element.expanding:
- # coercing to expanding at the moment to work with the
- # lambda system. not sure if this is the right approach.
- # is there a valid use case to send a single non-expanding
- # param to IN? check for ARRAY type?
- element = element._clone(maintain_key=True)
- element.expanding = True
-
+ # previously we were adding expanding flags here but
+ # we now do this in the compiler where we have more context
+ # see compiler.py -> _render_in_expr_w_bindparam
return element
else:
return element