summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2018-10-04 13:49:42 -0400
committerGerrit Code Review <gerrit@ci.zzzcomputing.com>2018-10-04 13:49:42 -0400
commit96bb76222e1f612af7bd425ef5b4f208e10a255d (patch)
tree111fac4deb807af1558b71f7f11d290fe8dc84ea /lib/sqlalchemy/dialects
parent56fb68ca8620a211ca29b3d47d649dfa332d354a (diff)
parentaa2128427064a2bdeaeff5dc946ecbb3727c90aa (diff)
downloadsqlalchemy-96bb76222e1f612af7bd425ef5b4f208e10a255d.tar.gz
Merge "Support tuples of heterogeneous types for empty expanding IN"
Diffstat (limited to 'lib/sqlalchemy/dialects')
-rw-r--r--lib/sqlalchemy/dialects/mysql/base.py14
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py13
2 files changed, 20 insertions, 7 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py
index cd17bcdc4..07eca78bb 100644
--- a/lib/sqlalchemy/dialects/mysql/base.py
+++ b/lib/sqlalchemy/dialects/mysql/base.py
@@ -1180,8 +1180,18 @@ class MySQLCompiler(compiler.SQLCompiler):
fromhints=from_hints, **kw)
for t in [from_table] + extra_froms)
- def visit_empty_set_expr(self, type_):
- return 'SELECT 1 FROM (SELECT 1) as _empty_set WHERE 1!=1'
+ def visit_empty_set_expr(self, element_types):
+ return (
+ "SELECT %(outer)s FROM (SELECT %(inner)s) "
+ "as _empty_set WHERE 1!=1" % {
+ "inner": ", ".join(
+ "1 AS _in_%s" % idx
+ for idx, type_ in enumerate(element_types)),
+ "outer": ", ".join(
+ "_in_%s" % idx
+ for idx, type_ in enumerate(element_types))
+ }
+ )
class MySQLDDLCompiler(compiler.DDLCompiler):
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index 11fcc41d5..5251a000d 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -1485,14 +1485,17 @@ class PGCompiler(compiler.SQLCompiler):
if escape else ''
)
- def visit_empty_set_expr(self, type_, **kw):
+ def visit_empty_set_expr(self, element_types):
# cast the empty set to the type we are comparing against. if
# we are comparing against the null type, pick an arbitrary
# datatype for the empty set
- if type_._isnull:
- type_ = INTEGER()
- return 'SELECT CAST(NULL AS %s) WHERE 1!=1' % \
- self.dialect.type_compiler.process(type_, **kw)
+ return 'SELECT %s WHERE 1!=1' % (
+ ", ".join(
+ "CAST(NULL AS %s)" % self.dialect.type_compiler.process(
+ INTEGER() if type_._isnull else type_,
+ ) for type_ in element_types or [INTEGER()]
+ ),
+ )
def render_literal_value(self, value, type_):
value = super(PGCompiler, self).render_literal_value(value, type_)