Details
-
Type:
Bug
-
Status: Closed (View Workflow)
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 10.2.0
-
Component/s: Parser
-
Labels:None
-
Sprint:10.2.0-1
Description
There is a shift/reduce conflict in the grammar in sql_yacc.yy when parsing a query like this:
CREATE FUNCTION f1() RETURNS CHAR (....); |
The parser does not know what the left parenthesis means, either it continues the data type specifying the length:
CREATE FUNCTION f1() RETURNS CHAR(1) ...; |
or it's a CHAR with no length (i.e. length==1) followed by a start of a subselect:
CREATE FUNCTION f1() RETURNS CHAR (SELECT 'a'); |
Note, the latter query is accepted by the parse, but it's syntactically is wrong. A correct query would be:
CREATE FUNCTION f1() RETURNS CHAR RETURN (SELECT 'a'); |
Fortunately, currently the wrong query returns an error anyway:
ERROR 1415 (0A000) at line 3: Not allowed to return a result set from a function
|
But it should be fixed to return a syntax error instead, because the RETURN keyword is obviously missing.
An idea for a fix:
The sp_proc_stmt rule in sql_yacc.yy should be split into two parts:
1. statements that are allowed in RETURN clause
2. statements that are not allowed in RETURN clause
Subselect should go into #2.
This will fix the error message, as well as remove some shift/reduce conflicts.