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

DEFAULT() doesn't behave as documented

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • 10.5.5
    • N/A
    • Documentation
    • None

    Description

      Documentation for default function says:

      "If the column has no default value, NULL is returned."

      https://mariadb.com/kb/en/default/

      A test shows that:

      1. [snippet 1] If the column has no default and it is NULLable and the table is empty, no row is returned, even if we are also selecting another expression.
      2. [snippet 2] If the column has no default value and it's not NULLable, an error is returned.

      MariaDB [test]> CREATE OR REPLACE TABLE t (x INT NULL, y INT NOT NULL);
      Query OK, 0 rows affected (0.013 sec)
       
      MariaDB [test]> SELECT DEFAULT(x), 1 FROM t;
      Empty set (0.001 sec)
      

      This looks like a bug to me.

      MariaDB [test]> SELECT @@sql_mode;
      +------------+
      | @@sql_mode |
      +------------+
      |            |
      +------------+
      1 row in set (0.000 sec)
       
      MariaDB [test]> SELECT DEFAULT(y) FROM t;
      ERROR 1364 (HY000): Field 'y' doesn't have a default value
      

      This makes sense to me because no default != NULL, but in that case the docs should be adjusted.

      Attachments

        Activity

          People

            greenman Ian Gilfillan
            f_razzoli Federico Razzoli
            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.