On Fri, 27 Nov 2026 at 13:55, Andrey Borodin <[email protected]> wrote: > > Hi Kirill, > > On 25 Nov 2026, Kirill Reshke wrote: > > There are more cases with wrong results (all because of subquery-style > > query rewrite, all cures with 0001). > > The SQL draft I checked specifies this subquery rewrite: 7.18 > "<search or cycle clause>", Syntax Rule 8, puts the cycle-mark filter > in the outer WHERE, as our current implementation does.
OK, should we follow this? Can we rewrite the query this way preserving window func semantics? > Also, 7.17 "<query expression>", SR 3)j)ix)5)C)II, prohibits window > functions in the recursive SELECT. Supporting them is our extension, > so the standard does not prescribe the window results in your example. (§7.17, Syntax Rule 5(c)(II)) prohibits windows functions in WITH RECURSIVE even without CYCLE (at least from my reading). Also here was previous diction about similar problems [0]. At time, postgres didn't forbid this case just because SQL standard says its disallowed. .... Another issue found while luring SQL draft copy WITH RECURSIVE t(n) AS ( VALUES (1) UNION ALL SELECT n + 1 FROM t WHERE n < 2 ) CYCLE n SET mark TO TRUE DEFAULT TRUE USING path SELECT n, mark FROM t; §7.18, Syntax Rule 6(c): ..CMV and CMD shall be literals and CMV shall not be equal to CMD... - but postgres allows TO TRUE DEFAULT TRUE. We can add this here or fix [1] [0] https://www.postgresql.org/message-id/17581.1230482868%40sss.pgh.pa.us [1] https://wiki.postgresql.org/wiki/PostgreSQL_vs_SQL_Standard -- Best regards, Kirill Reshke
