feat: add CTE (WITH clause) support to SQL executor#320
Open
DidelotK wants to merge 3 commits intoeddiethedean:mainfrom
Open
feat: add CTE (WITH clause) support to SQL executor#320DidelotK wants to merge 3 commits intoeddiethedean:mainfrom
DidelotK wants to merge 3 commits intoeddiethedean:mainfrom
Conversation
Add support for Common Table Expressions (CTEs) in SQL queries, enabling queries like: WITH cte AS (SELECT * FROM table WHERE x > 0) SELECT * FROM cte Implementation: - Parser: detect WITH queries, parse CTE definitions with balanced parenthesis - Executor: execute CTEs and store in temp views, then execute main query - Table loading: check temp views before session.table() lookup Features: - Single and multiple CTEs in one query - Chained CTEs (CTE referencing another CTE) - CTEs with filtering, aggregation, and column selection - Case-insensitive WITH keyword - Proper cleanup of temp views after execution Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove unused `pos` variable in parser.py - Remove unused imports (cast, pytest, DataFrame) in test_sql_cte.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This was referenced Jan 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add support for Common Table Expressions (CTEs) in SQL queries, enabling queries like:
Changes
Parser (
parser.py):WITHdetection in_detect_query_type()(before UNION check)WITHin_parse_components()_parse_with_query()method that parses CTE definitions using balanced parenthesis countingExecutor (
executor.py):WITHcase inexecute()method_execute_with()method that executes CTEs and stores results in temp viewssession.table()lookupFeatures Supported
WITH cte AS (...) SELECT * FROM cteWITH cte1 AS (...), cte2 AS (...) SELECT * FROM cte2WITHkeywordTest Plan
Known Limitations
🤖 Generated with Claude Code