Closed mingodad closed 3 months ago
It really can't do its thing without column names. I could use inferred column names. This would essentially rewrite the above as
hierarchy(*) AS (
SELECT id, parent_id, level
FROM input
WHERE id = 3 -- start point
UNION ALL
-- stop when join result is empty set (0 rows returned)
SELECT i.id, i.parent_id, i.level
FROM hierarchy h -- previous result set stored in temporary table
JOIN input i
ON i.id = h.parent_id
)
SELECT * FROM hierarchy;
Which means "use the column names of the inner select"
I'm only pointing out that it differs from sqlite3/postgresql
here.
I did an experiment in the grammar to accept it by adding star
behind the curtains:
cte_decl:
name '(' name_list ')' { $cte_decl = new_ast_cte_decl(CS, $name, $name_list); }
| name '(' '*' ')' { $cte_decl = new_ast_cte_decl(CS, $name, new_ast_star(CS)); }
| name { $cte_decl = new_ast_cte_decl(CS, $name, new_ast_star(CS)); }
;
I just did exactly the same:
https://github.com/ricomariani/CG-SQL-author/commit/d91c2315b90d2587c6957ce6d3f411352eddbf46
That's actually a pretty good approach for CQL.
Example:
SQLite3 output:
CQL output: