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

Method test_union

test/sql/test_cte.py:759–795  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

757 )
758
759 def test_union(self):
760 orders = table("orders", column("region"), column("amount"))
761
762 regional_sales = select(orders.c.region, orders.c.amount).cte(
763 "regional_sales"
764 )
765
766 s = select(regional_sales.c.region).where(
767 regional_sales.c.amount > 500
768 )
769
770 self.assert_compile(
771 s,
772 "WITH regional_sales AS "
773 "(SELECT orders.region AS region, "
774 "orders.amount AS amount FROM orders) "
775 "SELECT regional_sales.region "
776 "FROM regional_sales WHERE "
777 "regional_sales.amount > :amount_1",
778 )
779
780 s = s.union_all(
781 select(regional_sales.c.region).where(
782 regional_sales.c.amount < 300
783 )
784 )
785 self.assert_compile(
786 s,
787 "WITH regional_sales AS "
788 "(SELECT orders.region AS region, "
789 "orders.amount AS amount FROM orders) "
790 "SELECT regional_sales.region FROM regional_sales "
791 "WHERE regional_sales.amount > :amount_1 "
792 "UNION ALL SELECT regional_sales.region "
793 "FROM regional_sales WHERE "
794 "regional_sales.amount < :amount_2",
795 )
796
797 def test_union_cte_aliases(self):
798 orders = table("orders", column("region"), column("amount"))

Callers

nothing calls this directly

Calls 7

tableFunction · 0.90
columnFunction · 0.90
selectFunction · 0.90
assert_compileMethod · 0.80
cteMethod · 0.45
whereMethod · 0.45
union_allMethod · 0.45

Tested by

no test coverage detected