parser icon indicating copy to clipboard operation
parser copied to clipboard

Failed to parse WHERE / GROUP BY clauses in a SELECT statement without a FROM table

Open kennytm opened this issue 6 years ago • 3 comments

These SQLs:

select 1 where true;
select 1 group by 1;
select 1 having true;

All return one row with the value 1 on MySQL 8.0 (also tested on PostgreSQL 9.6 and SQLite 3.24 with the same behavior), but failed to parse on TiDB 2.1.1 and master:

mysql> select 1 where true;
ERROR 1105 (HY000): line 1 column 14 near " true" (total length 19)
mysql> select 1 group by 1;
ERROR 1105 (HY000): line 1 column 14 near " by 1" (total length 19)
mysql> select 1 having true;
ERROR 1105 (HY000): line 1 column 15 near " true" (total length 20)

Table-less queries which are correctly accepted by TiDB:

select 1 order by 1;
select 1 limit 1;

kennytm avatar Dec 23 '18 11:12 kennytm

Let me fix it please :smile:

zhenghaoz avatar Oct 22 '19 00:10 zhenghaoz

Hey, I wanna fix this issue. I read the discussion, and wondering:

  1. What is the conclusion of these SQL shown in pr #587 :
SELECT @@autocommit limit 1; -- @@autocommit:1 or `@@autocommit limit 1`:1?
select 1 where true group by 1 having 1>0; -- Throw an error? Or just return 1:1?
  1. If the case is going to be fixed, is it ok to just fix the SQL shown in this pr? Or maybe the overwrite of SELECT statement is needed?

If there is a clear conclusion, I'll be happy to fix it if I can. Otherwise maybe I can go out and see other cases ^_^.

PS: I also read doc in mysql (https://dev.mysql.com/doc/refman/8.0/en/select.html), no clear conclusion found.

wangggong avatar Jul 11 '20 14:07 wangggong

Follow MySQL's behavior on doubt.

mysql> SELECT @@autocommit limit 1;
+--------------+
| @@autocommit |
+--------------+
|            1 |
+--------------+
1 row in set (0.00 sec)

mysql> select 1 where true group by 1 having 1>0;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.01 sec)

kennytm avatar Jul 11 '20 16:07 kennytm