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

Subquery in expressions support #298

Open
m0003r opened this issue Apr 7, 2020 · 2 comments
Open

Subquery in expressions support #298

m0003r opened this issue Apr 7, 2020 · 2 comments

Comments

@m0003r
Copy link
Contributor

m0003r commented Apr 7, 2020

It seems to subqueries are poorly supported

Some examples first:

They are not parsed at all
SELECT * FROM (SELECT * FROM b) a

results in

...
PhpMyAdmin\SqlParser\Components\Expression Object
(
    [database] =>
    [table] =>
    [column] =>
    [expr] => (SELECT * FROM b)
    [alias] => a
    [function] =>
    [subquery] => SELECT
)
...
not even extracted properly (see #254)
SELECT * FROM a WHERE a.field IN (SELECT * FROM b)

results in

...
...
PhpMyAdmin\SqlParser\Components\Condition Object
(
    [identifiers] => Array
        (
            [0] => a
            [1] => field
            [2] => b
        )

    [isOperator] =>
    [expr] => a.field IN (SELECT * FROM b)
)
...

So I have an idea. May be there must be separate ExpressionParser generating AST for expression? Those (including me) who needed parsed expression can use it (and extract subselects, and parse it with regular parser), and there will be no compatibility break.

Does it sounds as a good plan? If it does, I would like to implement it.

@m0003r m0003r changed the title Subquery support Subquery in expressions support Apr 7, 2020
@williamdes
Copy link
Member

For me it sound a good plan, I would be happy to see a PR ;)
@devenbansod any thoughts on this one ?

@devenbansod
Copy link
Member

@m0003r Yes. Definitely sounds like a plan. Please feel free to make a PR and I would be happy to help review.

We do have a https://github.com/phpmyadmin/sql-parser/blob/master/src/Components/Expression.php and https://github.com/phpmyadmin/sql-parser/blob/master/src/Components/CaseExpression.php which do parse normal expressions. You can decide on whether you can reuse any functionality (or look for inspiration on how to handle a few things) from these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants