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

With clause parsing support #83

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

soulstompp
Copy link

This change adds the ability to parse CTEs included with a SELECT anywhere that a nested_selection (compound or otherwise) is allowed. This change addresses #77.

@soulstompp
Copy link
Author

This pull request is built off of the branch in #82. I needed to be able to parse nested compound statements in order to parse the WITH clauses.

@soulstompp
Copy link
Author

I realized that this might need a little more work, since the following query would currently parse gives a syntax error in MySQL 8.0.30:

WITH cte1 AS (SELECT a, b FROM table1) SELECT b, d FROM cte1 UNION ALL WITH cte2 AS (SELECT a, b FROM table1) SELECT b, d FROM cte2;

Since the two withs cannot occur at the same level. For example this is acceptable:

(WITH cte1 AS (SELECT a, b FROM table1) SELECT b, d FROM cte1) UNION ALL (WITH cte2 AS (SELECT a, b FROM table1) SELECT b, d FROM cte2);

And it's not really that the WITH can't come after this UNION since this is syntactically correct:
SELECT 1 AS a, 2 AS b UNION (WITH cte1 AS (SELECT 2 AS a, 1 AS b) SELECT a, b FROM cte1);

Considering all of that, I am not sure this is really something the parser should concern itself with.

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