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

refactor(sqlparser/binder): extra parentheses around subquery are handled inconsistently #14502

Open
xiangjinwu opened this issue Jan 11, 2024 · 1 comment
Assignees
Milestone

Comments

@xiangjinwu
Copy link
Contributor

xiangjinwu commented Jan 11, 2024

BoundQuery could be created for each parenthesis, even though they are not considered as a Subquery

I see.

In the non-subquery or scalar-subquery case, extra levels of parentheses are Expr::Nested, including 1 + (((select 2))). There is a single Expr::Subquery and a single Query. This covers 1 + (((select 2) + 3) + 4).

But for subqueries with its own syntax, extra levels of parentheses are SetExpr::Query, including exists(((select 2))). There is a single Expr::Subquery with multiple Query levels, to accommodate exists(((select 2) union (select 3)) union (select 4))

Let me open an issue to track whether these two should be unified, especially the unsupported 1 < any(((select 2))) is parsed as case A today be may belong to case B.

Originally posted by @xiangjinwu in #14430 (review)

To view the parsed ast: cargo run --bin sqlparser <<< '(((select 2)));'

@github-actions github-actions bot added this to the release-1.7 milestone Jan 11, 2024
@xiangjinwu
Copy link
Contributor Author

The Expr::Subquery case is expected to allow SetExpr::Query as well, as in PostgreSQL:

test=# select 10 + (((select 2) union (select 3)) except (select 2));
 ?column? 
----------
       13
(1 row)

However, our sqlparser is reporting an error:

sql parser error: Expected ), found: union at line:1, column:31

To summarize:

  • exists(((select 2) union (select 3)) union (select 4)) uses SetExpr::Query
  • exists(((select 2))) uses SetExpr::Query
  • 10 + (((select 2) union (select 3)) except (select 2)) should use SetExpr::Query but is buggy today.
  • 1 + (((select 2) + 3) + 4) uses Expr::Nested
  • 1 + (((select 2))) can use both. It is Expr::Nested today but may or may not switch to SetExpr::Query after bug fix.

@xiangjinwu xiangjinwu self-assigned this Mar 6, 2024
@xiangjinwu xiangjinwu modified the milestones: release-1.7, release-1.8 Mar 6, 2024
@xiangjinwu xiangjinwu modified the milestones: release-1.8, release-1.9 Apr 8, 2024
@xiangjinwu xiangjinwu modified the milestones: release-1.9, release-1.10 May 13, 2024
@xiangjinwu xiangjinwu modified the milestones: release-1.10, release-1.11 Jul 10, 2024
@xiangjinwu xiangjinwu modified the milestones: release-2.1, release-2.2 Oct 17, 2024
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

1 participant