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)
| 295 | ) |
| 296 | |
| 297 | def test_recursive_union_no_alias_two(self): |
| 298 | """ |
| 299 | |
| 300 | pg'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, |