Bug #84638 Missing FROM clause returns error when using INTO at the end of the statement
Submitted: 24 Jan 2017 12:40 Modified: 26 Jan 2017 17:15
Reporter: Arthur Tokarchuk Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:5.6, 5.7 OS:Any
Assigned to: CPU Architecture:Any

[24 Jan 2017 12:40] Arthur Tokarchuk
Description:
When using SELECT with INTO at the end of the statement, MySQL returns ERROR 1064 (42000) if there is no FROM clause and INTO is separated from SELECT by some other statements.

How to repeat:
Works fine:
mysql> select 1 into @a;
Query OK, 1 row affected (0.00 sec)

Error:
mysql> select 1 limit 1 into @a;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'into @a' at line 1

Error:
mysql> select 1 union select 2 limit 1 into @a;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'into @a' at line 1

Works fine:
mysql> select 1 from t1 union select 2 from t1 limit 1 into @a;
Query OK, 1 row affected (0.00 sec)

Error:
mysql> select 1 from t1 union select 2 limit 1 into @a;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'into @a' at line 1

Works fine:
mysql> select 1 union select 2 from t1 limit 1 into @a;
Query OK, 1 row affected (0.00 sec)

t1 is:
mysql> create table t1(a int);
Query OK, 0 rows affected (0.05 sec)

mysql> insert into t1 values(1);
Query OK, 1 row affected (0.02 sec)
[26 Jan 2017 17:15] MySQL Verification Team
Hi!

In the first implementation of the INTO @var, which was made back in mysql-5.0, this construct, INTO @var1, @var2, could have gone only after SELECT list.

Now, I see both in our manual, paragraph "13.2.9.1 SELECT ... INTO Syntax", as well as in our Bison code, that INTO variables_list is located at the same spot as INTO files_of_different_format.

Hence, I think that this is a bug in our parser. I have tested with both , 5.6 and 5.7.

Verified.
[30 Jan 2017 6:47] Roy Lyseng
Sinisa, you should have checked with 8.0 too. After Gleb's refactoring of the parser, these statements are all accepted. I suggest that you close the bug as fixed in 8.0.