summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-03-21 10:57:40 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-03-21 10:57:40 -0400
commit07a4b6cbcda6e6ee6e67893c5a5d2fd01e5f125f (patch)
treea28aac49f1f8fd7aef5ae3ed85a2bd9ce98978d1 /test/sql
parent732c613eeb890e7b7cbd04750468dac584151a31 (diff)
downloadsqlalchemy-07a4b6cbcda6e6ee6e67893c5a5d2fd01e5f125f.tar.gz
- Fixed bug where the negation of an EXISTS expression would not
be properly typed as boolean in the result, and also would fail to be anonymously aliased in a SELECT list as is the case with a non-negated EXISTS construct. fixes #3682
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_compiler.py15
-rw-r--r--test/sql/test_selectable.py27
2 files changed, 42 insertions, 0 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index 8e75638a2..66612eb33 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -638,6 +638,21 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL):
"myothertable.otherid = :otherid_2)) AS anon_1"
)
+ self.assert_compile(
+ select([exists([1])]),
+ "SELECT EXISTS (SELECT 1) AS anon_1"
+ )
+
+ self.assert_compile(
+ select([~exists([1])]),
+ "SELECT NOT (EXISTS (SELECT 1)) AS anon_1"
+ )
+
+ self.assert_compile(
+ select([~(~exists([1]))]),
+ "SELECT NOT (NOT (EXISTS (SELECT 1))) AS anon_1"
+ )
+
def test_where_subquery(self):
s = select([addresses.c.street], addresses.c.user_id
== users.c.user_id, correlate=True).alias('s')
diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py
index 7203cc5a3..94e4ac024 100644
--- a/test/sql/test_selectable.py
+++ b/test/sql/test_selectable.py
@@ -2217,6 +2217,33 @@ class ResultMapTest(fixtures.TestBase):
[Boolean]
)
+ def test_plain_exists(self):
+ expr = exists([1])
+ eq_(type(expr.type), Boolean)
+ eq_(
+ [type(entry[-1]) for
+ entry in select([expr]).compile()._result_columns],
+ [Boolean]
+ )
+
+ def test_plain_exists_negate(self):
+ expr = ~exists([1])
+ eq_(type(expr.type), Boolean)
+ eq_(
+ [type(entry[-1]) for
+ entry in select([expr]).compile()._result_columns],
+ [Boolean]
+ )
+
+ def test_plain_exists_double_negate(self):
+ expr = ~(~exists([1]))
+ eq_(type(expr.type), Boolean)
+ eq_(
+ [type(entry[-1]) for
+ entry in select([expr]).compile()._result_columns],
+ [Boolean]
+ )
+
def test_column_subquery_plain(self):
t = self._fixture()
s1 = select([t.c.x]).where(t.c.x > 5).as_scalar()