MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_recursive_union_no_alias_two

Method test_recursive_union_no_alias_two

test/sql/test_cte.py:297–327  ·  view source on GitHub ↗

pg's example: .. sourcecode:: sql WITH RECURSIVE t(n) AS ( VALUES (1) UNION ALL SELECT n+1 FROM t WHERE n < 100 ) SELECT sum(n) FROM t;

(self)

Source from the content-addressed store, hash-verified

295 )
296
297 def test_recursive_union_no_alias_two(self):
298 """
299
300 pg&#x27;s example:
301
302 .. sourcecode:: sql
303
304 WITH RECURSIVE t(n) AS (
305 VALUES (1)
306 UNION ALL
307 SELECT n+1 FROM t WHERE n < 100
308 )
309 SELECT sum(n) FROM t;
310
311 """
312
313 # I know, this is the PG VALUES keyword,
314 # we're cheating here. also yes we need the SELECT,
315 # sorry PG.
316 t = select(func.values(1).label("n")).cte("t", recursive=True)
317 t = t.union_all(select(t.c.n + 1).where(t.c.n < 100))
318 s = select(func.sum(t.c.n))
319 self.assert_compile(
320 s,
321 "WITH RECURSIVE t(n) AS "
322 "(SELECT values(:values_1) AS n "
323 "UNION ALL SELECT t.n + :n_1 AS anon_1 "
324 "FROM t "
325 "WHERE t.n < :n_2) "
326 "SELECT sum(t.n) AS sum_1 FROM t",
327 )
328
329 def test_recursive_union_alias_two(self):
330 # I know, this is the PG VALUES keyword,

Callers

nothing calls this directly

Calls 8

selectFunction · 0.90
assert_compileMethod · 0.80
cteMethod · 0.45
labelMethod · 0.45
valuesMethod · 0.45
union_allMethod · 0.45
whereMethod · 0.45
sumMethod · 0.45

Tested by

no test coverage detected