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

Unexpected result of function LOCATE when one of arguments is NULL

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 12.0.2
    • None
    • None
    • None
    • Ubuntu 24.04

    Description

      Hi,

      Based on the document https://mariadb.com/docs/server/reference/sql-functions/string-functions/locate, if any argument of LOCATE is NULL, LOCATE returns NULL.

      However, it returns 0 in the following test case:

      ```
      CREATE TABLE t0(c0 REAL);
      CREATE TABLE IF NOT EXISTS t1 LIKE t0;
      INSERT INTO t0 VALUES (-1);
      SELECT t1.c0, LOCATE(t0.c0, t0.c0, t1.c0) FROM t0 LEFT JOIN t1 ON false;

      c0 LOCATE(t0.c0, t0.c0, t1.c0)
      NULL 0
      ```
      I tried this in MySQL and found it returns NULL.

      Attachments

        Activity

          People

            Unassigned Unassigned
            ChiZhang Chi Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            1 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.