[MDEV-9976] Parsing problems related to Window functions Created: 2016-04-24  Updated: 2017-02-02  Resolved: 2017-02-02

Status: Closed
Project: MariaDB Server
Component/s: Optimizer - Window functions, Parser
Affects Version/s: 10.2
Fix Version/s: 10.2.4

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: 10.2-ga


 Description   

This works:

MariaDB [test]> SELECT sum(salary) OVER (PARTITION BY salary ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) FROM employee_salary;
+-----------------------------------------------------------------------------------------+
| sum(salary) OVER (PARTITION BY salary ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) |
+-----------------------------------------------------------------------------------------+
|                                                                                    5000 |
|                                                                                   10000 |
|                                                                                   20000 |
|                                                                                   30000 |
|                                                                                   80000 |
|                                                                                   40000 |
|                                                                                  150000 |
|                                                                                  100000 |
|                                                                                   50000 |
+-----------------------------------------------------------------------------------------+
9 rows in set (0.00 sec)

But this does not work and returns a rather vague syntax error:

SELECT sum(salary) OVER (ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) FROM employee_salary;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) FROM employee_salary' at line 1

It works in PostgreSQL:

postgres=# SELECT sum(salary) OVER (ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) FROM employee_salary;
  sum   
--------
 295000
 285000
 265000
 235000
 195000
 155000
 105000
  55000
   5000
(9 rows)

Standard specifies:

<window specification> ::=
  <left paren> <window specification details> <right paren>
<window specification details> ::=
  [ <existing window name> ]
      [ <window partition clause> ]
      [ <window order clause> ]
      [ <window frame clause> ]
<existing window name> ::=
  <window name>



 Comments   
Comment by Vicențiu Ciorbaru [ 2016-09-17 ]

This issue is related to MDEV-9935. This should not be a syntax error however. The grammar needs to change in this case.

Comment by Igor Babaev [ 2017-02-02 ]

The fix for this bug was pushed into the 10.2 tree

Generated at Thu Feb 08 07:38:44 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.