Bug #22312 Syntax error in expression with INTERVAL()
Submitted: 13 Sep 2006 13:57 Modified: 18 Dec 2007 4:24
Reporter: Duke Vandyuk Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Parser Severity:S3 (Non-critical)
Version:4.1, 5.0, 5.1 OS:Any
Assigned to: Davi Arnaut CPU Architecture:Any

[13 Sep 2006 13:57] Duke Vandyuk
Description:
Seems an error in syntax analyzer when INTERVAL() with arythmetical expressions in SELECT query. It's order-sensitive:

X + INTERVAL() - is working, but
INTERVAL() + X - gives an systax error.

How to repeat:
mysql> SELECT 1 + INTERVAL(1,0,1,2);
+-----------+-----------------------+
| version() | 1 + interval(1,0,1,2) |
+-----------+-----------------------+
| 5.0.18    |                     3 |
+-----------+-----------------------+

mysql> SELECT INTERVAL(1,1,2,3) + 1;
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 '' at line 1
[13 Sep 2006 15:04] Valeriy Kravchuk
Thank you for a problem report. Please, try to repeat with latest versions, 5.0.24a and 4.1.21, and inform about the results.
[13 Sep 2006 15:56] Duke Vandyuk
Tested at least on 4.1.21 and 5.0.18 - effect is the same.
[13 Sep 2006 19:28] Sveta Smirnova
Thank you for the report.

Verified as described on Linux using current BK sources of all 3 branches.
[24 Jan 2007 15:42] Scott Noyes
Also note that (INTERVAL()) + X works, while INTERVAL() + X does not
[30 Nov 2007 11:34] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/38947

ChangeSet@1.2672, 2007-11-30 09:34:25-02:00, davi@mysql.com +3 -0
  Bug#22312 Syntax error in expression with INTERVAL()
  
  Parser rejects valid INTERVAL() expressions when associated with
  arithmetic operators. The problem is the way in which the expression
  and interval grammar rules were organized caused shift/reduce conflicts.
  
  The solution is to tweak the interval rules to avoid shift/reduce
  conflicts by removing the broken interval_expr rule and explicitly
  specify it's content where necessary.
  
  Original fix by Davi Arnaut, revised and improved rules by Marc Alff
[30 Nov 2007 15:49] Marc ALFF
Approved by email
Patch is OK to push
[6 Dec 2007 9:59] Bugs System
Pushed into 5.1.23-rc
[6 Dec 2007 10:01] Bugs System
Pushed into 6.0.5-alpha
[18 Dec 2007 4:24] Paul DuBois
Noted in 5.1.23, 6.0.5 changelogs.

The parser treated the INTERVAL() function incorrectly, leading to
situations where syntax errors could result depending on which side
of an arithmetic operator the function appeared.