Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-9976

Parsing problems related to Window functions

    XMLWordPrintable

Details

    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>
      

      Attachments

        Activity

          People

            igor Igor Babaev
            elenst Elena Stepanova
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.