MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_recursive_union_no_alias_four

Method test_recursive_union_no_alias_four

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

Source from the content-addressed store, hash-verified

392 )
393
394 def test_recursive_union_no_alias_four(self):
395 # like test one and three, but let's refer
396 # previous version of "cte". here we test
397 # how the compiler resolves multiple instances
398 # of "cte".
399
400 s1 = select(literal(0).label("x"))
401 cte = s1.cte(name="cte", recursive=True)
402
403 bar = select(cte).cte("bar")
404 cte = cte.union_all(select(cte.c.x + 1).where(cte.c.x < 10))
405
406 # outer cte rendered first, then bar, which
407 # includes "inner" cte
408 s2 = select(cte, bar)
409 self.assert_compile(
410 s2,
411 "WITH RECURSIVE cte(x) AS "
412 "(SELECT :param_1 AS x UNION ALL "
413 "SELECT cte.x + :x_2 AS anon_1 "
414 "FROM cte WHERE cte.x < :x_3), "
415 "bar AS (SELECT cte.x AS x FROM cte) "
416 "SELECT cte.x, bar.x AS x_1 FROM cte, bar",
417 )
418
419 # bar rendered, only includes "inner" cte,
420 # "outer" cte isn't present
421 s2 = select(bar)
422 self.assert_compile(
423 s2,
424 "WITH RECURSIVE cte(x) AS "
425 "(SELECT :param_1 AS x), "
426 "bar AS (SELECT cte.x AS x FROM cte) "
427 "SELECT bar.x FROM bar",
428 )
429
430 # bar rendered, but then the "outer"
431 # cte is rendered.
432 s2 = select(bar, cte)
433 self.assert_compile(
434 s2,
435 "WITH RECURSIVE bar AS (SELECT cte.x AS x FROM cte), "
436 "cte(x) AS "
437 "(SELECT :param_1 AS x UNION ALL "
438 "SELECT cte.x + :x_2 AS anon_1 "
439 "FROM cte WHERE cte.x < :x_3) "
440 "SELECT bar.x, cte.x AS x_1 FROM bar, cte",
441 )
442
443 def test_recursive_union_alias_four(self):
444 # like test one and three, but let's refer

Callers

nothing calls this directly

Calls 7

selectFunction · 0.90
literalFunction · 0.90
assert_compileMethod · 0.80
labelMethod · 0.45
cteMethod · 0.45
union_allMethod · 0.45
whereMethod · 0.45

Tested by

no test coverage detected