Recursive CTE with CYCLE in postgres
sttts opened this issue · 0 comments
sttts commented
Is your feature request related to a problem? Please describe.
Postgres supports CYCLE detection in recursive CTEs, compare https://www.postgresql.org/docs/current/queries-with.html#QUERIES-WITH-CYCLE:
WITH RECURSIVE search_graph(id, link, data, depth) AS (
SELECT g.id, g.link, g.data, 1
FROM graph g
UNION ALL
SELECT g.id, g.link, g.data, sg.depth + 1
FROM graph g, search_graph sg
WHERE g.id = sg.link
) CYCLE id SET is_cycle USING path
SELECT * FROM search_graph;
This should be expressible in goqu.
Describe the solution you'd like
goqu.From(...).WithRecursive("closure", exp).Cycle(goqu.I("id"), goqu.I("is_cycle"), goqu.I("path"))
Describe alternatives you've considered
Any other workaround like injecting a literal expression before the select would work too. Haven't found a way yet to do that.
Dialect
- postgres
- mysql
- sqlite3
Additional context
Add any other context or screenshots about the feature request here.