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

unix_timestamp(coalesce(timestamp_column)) returns NULL on '1970-01-01 00:00:00.000001'

    XMLWordPrintable

Details

    Description

      SET time_zone='+00:00';
      CREATE OR REPLACE TABLE t1 (a TIMESTAMP(6) NULL);
      INSERT INTO t1 VALUES ('1970-01-01 00:00:00.000001');
      SELECT unix_timestamp(a), unix_timestamp(coalesce(a)) FROM t1;
      

      +-------------------+-----------------------------+
      | unix_timestamp(a) | unix_timestamp(coalesce(a)) |
      +-------------------+-----------------------------+
      |          0.000001 |                        NULL |
      +-------------------+-----------------------------+
      

      • unix_timestamp(a) returns 0.000001, which is correct
      • unix_timestamp(coalesce(a)) returns NULL, which is wrong

      The problem resides in this code in Field_timestampf::val_native():

        // Check if it's '0000-00-00 00:00:00' rather than a real timestamp
        if (ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0)
        {
          to->length(0);
          return false;
      

      It considers all values with zero seconds as zero datetime. It's not enough. It should also check microseconds for zero.

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.