sql-parser icon indicating copy to clipboard operation
sql-parser copied to clipboard

Syntax error in subquery when used in SET

Open rusakov92 opened this issue 5 years ago • 2 comments

Hello,

I'm using the linter provided in this library and found out that when we use it on this query SET @test := (SELECT 1); it fails when we try to build the object \PhpMyAdmin\SqlParser\Statements\SetStatement from \PhpMyAdmin\SqlParser\Parser with the message "A new statement was found, but no delimiter between it and the previous one.".

The parser fails also when we try to build the \PhpMyAdmin\SqlParser\Statements\SelectStatement because we don't add ; at the end before the ), the error message is "Unexpected token.".

Both of the errors are thrown by \PhpMyAdmin\SqlParser\Statement::parse().

I'm happy to create a PR with a fix for this but I'm not entirely sure how the parsing works, can someone explain it to me and suggest a fix for this?

rusakov92 avatar Jul 02 '20 08:07 rusakov92

Hello @rusakov92
Thank you for the feedback! We would be happy to have a pull-request against QA branch I am afraid not to be able to explain more that the documentation already explains but if you find out on how to fix this we can definitely discuss the fix

williamdes avatar Jul 02 '20 16:07 williamdes

$ echo 'SET @test := (SELECT 1);' | ./bin/lint-query 
#1: A new statement was found, but no delimiter between it and the previous one. (near "SELECT" at position 14)
#2: Unexpected token. (near ")" at position 22)

williamdes avatar Aug 21 '21 01:08 williamdes