Skip to content

Add CYCLE clause support for recursive CTEs - #134

Open
heinrichf-cdgnm wants to merge 7 commits into
dimagi:mainfrom
heinrichf-cdgnm:cycle-clause
Open

Add CYCLE clause support for recursive CTEs#134
heinrichf-cdgnm wants to merge 7 commits into
dimagi:mainfrom
heinrichf-cdgnm:cycle-clause

Conversation

@heinrichf-cdgnm

@heinrichf-cdgnm heinrichf-cdgnm commented Jan 13, 2026

Copy link
Copy Markdown
Contributor

Converting the USING path column to Python is involved with psycopg2. psycopg3 will convert it to a list of string tuples. I tried my best to document this in the code and in the docs.

The columns the clause adds are read through cte.col, e.g. .annotate(is_cycle=cte.col.is_cycle).

Closes #96

@heinrichf-cdgnm

Copy link
Copy Markdown
Contributor Author

Pushed some cleanup on top.

  • The cycle argument is parsed into a CycleConfig in one place now, and invalid config raises instead of silently dropping the clause.
  • Column names are quoted, so mixed case names work.
  • is_cycle and path are no longer annotated onto the queryset by join(). They resolve through cte.col instead: .annotate(is_cycle=cte.col.is_cycle).
  • Two path assertions only held on psycopg2. They compare parsed values now.
  • Both doc examples were broken. Fixed, and they run on psycopg2 and psycopg 3.

@millerdev

Copy link
Copy Markdown
Contributor

@heinrichf-cdgnm Thank you for the contribution! I intend to review and hope to get this merged, but have been on vacation recently and am swamped with other work currently. Will get to it as soon as I can.

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

Successfully merging this pull request may close these issues.

Support for CYCLE clause

2 participants