Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive CTE with CYCLE in postgres #403

Open
1 of 3 tasks
sttts opened this issue Jan 15, 2024 · 0 comments
Open
1 of 3 tasks

Recursive CTE with CYCLE in postgres #403

sttts opened this issue Jan 15, 2024 · 0 comments
Assignees

Comments

@sttts
Copy link

sttts commented Jan 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants