pingcap / parser

A MySQL Compatible SQL Parser
Apache License 2.0
1.41k stars 489 forks source link

Some CTE statement is parse wrongly #1218

Closed wjhuang2016 closed 3 years ago

wjhuang2016 commented 3 years ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do? If possible, provide a recipe for reproducing the error.

    with cte as (select 1) select 1 union with cte as (select 1) select * from cte;
    with cte as (select 1) (select 1);
    with cte as (select 1) (select 1 union select 1);
    select * from (with cte as (select 1) select 1 union select 2) qn;
    select * from t where 1 > (with cte as (select 2) select * from cte);
    ( with cte(n) as ( select 1 ) select n+1 from cte union select n+2 from cte) union select 1;
    ( with cte(n) as ( select 1 ) select n+1 from cte) union select 1;
    ( with cte(n) as ( select 1 ) (select n+1 from cte)) union select 1;
  2. What did you expect to see?

The same as MySQL

  1. What did you see instead? Inconsistent with MySQL

  2. What version of TiDB SQL Parser are you using?

master

tisonkun commented 3 years ago

subtask of https://github.com/pingcap/tidb/issues/17472