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

Out of range error in AVG(YEAR(datetime)) due to a wrong data type

    XMLWordPrintable

Details

    Description

      I run this script:

      CREATE OR REPLACE TABLE t1 (a DATETIME);
      INSERT INTO t1 VALUES ('2001-01-01 10:20:30');
      CREATE OR REPLACE TABLE t2 AS SELECT AVG(YEAR(a)) FROM t1;
      

      It unexpectedly returns this error:

      ERROR 1264 (22003): Out of range value for column 'AVG(YEAR(a))' at row 2
      

      If I add LIMIT 0, the table gets created:

      CREATE OR REPLACE TABLE t2 AS SELECT AVG(YEAR(a)) FROM t1 LIMIT 0;
      SHOW CREATE TABLE t2;
      

      +-------+---------------------------------------------------------------------------------------------------------------------------------+
      | Table | Create Table                                                                                                                    |
      +-------+---------------------------------------------------------------------------------------------------------------------------------+
      | t2    | CREATE TABLE `t2` (
        `AVG(YEAR(a))` decimal(7,4) DEFAULT NULL
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci |
      +-------+---------------------------------------------------------------------------------------------------------------------------------+
      

      However, the column size is too small: a DECIMAL(7,4) can store up to 3 integer digits only.
      The expected column type is DECIMAL(8,4).

      Attachments

        Issue Links

          Activity

            People

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