fnc12 / sqlite_orm

❤️ SQLite ORM light header only library for modern C++
GNU Affero General Public License v3.0
2.19k stars 305 forks source link

why is this WITH not recursive? #1276

Closed juandent closed 1 month ago

juandent commented 1 month ago
        constexpr auto cnt = "cnt"_cte;
        constexpr auto x = "x"_col;
        auto ast = with(cnt(x).as(union_all(select(from), select(cnt->*x + 1, limit(end)))), select(cnt->*x));

Which produces SQL: WITH "cnt"("x") AS (SELECT 1 UNION ALL SELECT "cnt"."x" + 1 FROM "cnt" LIMIT 10) SELECT "cnt"."x" FROM "cnt"

It should be recursive correct?

trueqbit commented 1 month ago

You are right that the example should use with_recursive for clarity. However, SQLite does not care whether a CTE is marked as "recursive" or not. The recursive nature of a CTE depends on the select statement.

juandent commented 1 month ago

ok! thanks