sqlparser-rs icon indicating copy to clipboard operation
sqlparser-rs copied to clipboard

Parser fails when query contains redundant brackets

Open nataliezeller1 opened this issue 2 years ago • 4 comments

sqlparser fails with error "Expected ), found: t2" when the query contains redundant brackets, although the query is valid. Example (mysql query):

insert into t1 (id, name)
    (select t2.id, t2.name
     from t2
              left join t1 target
                        on target.id <=> t2.id
     where target.id is null)
on duplicate key update t1.id = t1.id

In the above example, the parser will return a successful result only after removing the brackets around the select.

nataliezeller1 avatar May 31 '23 09:05 nataliezeller1

Thank you for the report @nataliezeller1

Do you know of another system that supports this type of syntax?

alamb avatar Jun 02 '23 15:06 alamb

@alamb Redshift also supports this syntax, for example -

insert into t1 (id, name)
    (select t2.id, t2.name
     from t2
              left join t1 target
                        on target.id = t2.id
     where target.id is null);

Not sure about other DBs

nataliezeller1 avatar Jun 11 '23 06:06 nataliezeller1

@alamb Snowflake also supports this syntax.

yuval-illumex avatar Sep 24 '23 08:09 yuval-illumex

Sounds like it would be a good improvement to add to the parser

alamb avatar Oct 02 '23 11:10 alamb