Skip to content

Recognize CTEs declared with WITH RECURSIVE - #1670

Open
adityajai119 wants to merge 1 commit into
dbcli:mainfrom
adityajai119:fix-recursive-cte-extraction
Open

adityajai119 wants to merge 1 commit into
dbcli:mainfrom
adityajai119:fix-recursive-cte-extraction

Conversation

@adityajai119

Copy link
Copy Markdown

Description

extract_ctes expects the CTE identifier right after WITH. With WITH RECURSIVE, the next token is the RECURSIVE keyword, so the CTE is never picked up: extract_ctes("WITH RECURSIVE a AS (SELECT abc FROM xxx) SELECT * FROM a") returned ([], " a AS (SELECT abc FROM xxx) SELECT * FROM a"). Because of this, isolate_query_ctes treated the whole query as having no CTEs, and completion did not offer a recursive CTE or its columns in the main query.

The fix skips an optional RECURSIVE keyword before reading the CTE list. Added a test in tests/parseutils/test_ctes.py that fails on main and passes with the change.

Tested: pytest tests/parseutils/test_ctes.py tests/test_sqlcompletion.py (192 passed, 1 xfailed), ruff check and ruff format --check on the touched files.

Checklist

  • I searched the existing issues and pull requests on this topic and linked them above (see "Before Opening a Pull Request" in CONTRIBUTING.rst).
  • I've added this contribution to the changelog.rst.
  • I've added my name to the AUTHORS file (or it's already there).
  • I installed pre-commit hooks (pip install pre-commit && pre-commit install).
  • I verified that my changes work as expected (this may include manually testing them in your local environment, or in other available environments). Cross this out if not relevant (for example, if you're making a documentation change).
  • Please squash merge this pull request (uncheck if you'd like us to merge as multiple commits)

This branch has not been deployed

No deployments
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.

1 participant