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

MariaDB Rejects NULL Literal as Default Argument in LAG Window Function

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Critical
    • Resolution: Unresolved
    • 12.3.2, 12.2.2
    • None
    • None
    • Ubuntu 24.04 (Noble) x86_64

    Description

      MariaDB 12.3.2 incorrectly rejects the use of the NULL literal as the third (default) argument of the LAG window function, resulting in a syntax error (ERROR 1064).

      CREATE DATABASE lagtest; USE lagtest;
      CREATE TABLE llt (id INT PRIMARY KEY, p INT, o INT, v INT);
      INSERT INTO llt VALUES (1,1,10,5),(2,1,20,7),(3,1,30,9);
       
      -- OK: 2-argument form (implicit NULL)
      SELECT LAG(v, 1) OVER (PARTITION BY p ORDER BY o) FROM llt;
       
      -- OK: 3-argument form with integer default
      SELECT LAG(v, 1, 0) OVER (PARTITION BY p ORDER BY o) FROM llt;
       
      -- FAIL: 3-argument form with NULL literal
      SELECT LAG(v, 1, NULL) OVER (PARTITION BY p ORDER BY o) FROM llt;
      -- ERROR 1064 (42000): syntax error near ' NULL) OVER (...)'
      

      Observed Inconsistency
      MariaDB accepts:

      LAG(v, 1)
      LAG(v, 1, 0)

      but rejects:

      LAG(v, 1, NULL)

      This is a semantic inconsistency, as the first form implicitly uses NULL as the default value. The rejection of the explicit form indicates a parser-level bug rather than a missing feature.

      Attachments

        Activity

          People

            Unassigned Unassigned
            imchifan 刘启帆
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

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