sql-parser
sql-parser copied to clipboard
Subquery in expressions support
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.
For me it sound a good plan, I would be happy to see a PR ;) @devenbansod any thoughts on this one ?
@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.