MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / test_compound_grouping

Method test_compound_grouping

test/sql/test_compiler.py:2753–2886  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2751 )
2752
2753 def test_compound_grouping(self):
2754 s = select(column("foo"), column("bar")).select_from(text("bat"))
2755
2756 self.assert_compile(
2757 union(union(union(s, s), s), s),
2758 "((SELECT foo, bar FROM bat UNION SELECT foo, bar FROM bat) "
2759 "UNION SELECT foo, bar FROM bat) UNION SELECT foo, bar FROM bat",
2760 )
2761
2762 self.assert_compile(
2763 union(s, s, s, s),
2764 "SELECT foo, bar FROM bat UNION SELECT foo, bar "
2765 "FROM bat UNION SELECT foo, bar FROM bat "
2766 "UNION SELECT foo, bar FROM bat",
2767 )
2768
2769 self.assert_compile(
2770 union(s, union(s, union(s, s))),
2771 "SELECT foo, bar FROM bat UNION (SELECT foo, bar FROM bat "
2772 "UNION (SELECT foo, bar FROM bat "
2773 "UNION SELECT foo, bar FROM bat))",
2774 )
2775
2776 self.assert_compile(
2777 select(s.alias()),
2778 "SELECT anon_1.foo, anon_1.bar FROM "
2779 "(SELECT foo, bar FROM bat) AS anon_1",
2780 )
2781
2782 self.assert_compile(
2783 select(union(s, s).alias()),
2784 "SELECT anon_1.foo, anon_1.bar FROM "
2785 "(SELECT foo, bar FROM bat UNION "
2786 "SELECT foo, bar FROM bat) AS anon_1",
2787 )
2788
2789 self.assert_compile(
2790 select(except_(s, s).alias()),
2791 "SELECT anon_1.foo, anon_1.bar FROM "
2792 "(SELECT foo, bar FROM bat EXCEPT "
2793 "SELECT foo, bar FROM bat) AS anon_1",
2794 )
2795
2796 # this query sqlite specifically chokes on
2797 self.assert_compile(
2798 union(except_(s, s), s),
2799 "(SELECT foo, bar FROM bat EXCEPT SELECT foo, bar FROM bat) "
2800 "UNION SELECT foo, bar FROM bat",
2801 )
2802
2803 self.assert_compile(
2804 union(s, except_(s, s)),
2805 "SELECT foo, bar FROM bat "
2806 "UNION (SELECT foo, bar FROM bat EXCEPT SELECT foo, bar FROM bat)",
2807 )
2808
2809 # this solves it
2810 self.assert_compile(

Callers

nothing calls this directly

Calls 14

selectFunction · 0.90
columnFunction · 0.90
textFunction · 0.90
unionFunction · 0.90
except_Function · 0.90
intersectFunction · 0.90
assert_compileMethod · 0.80
select_fromMethod · 0.45
aliasMethod · 0.45
selectMethod · 0.45
limitMethod · 0.45
offsetMethod · 0.45

Tested by

no test coverage detected