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

TEXT column accepts too long literals as a default value

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.2, 10.3, 10.4
    • 10.4.5
    • Data types
    • None

    Description

      I create this table and intentionally pass a too long value as a default:

      EXECUTE IMMEDIATE 'CREATE OR REPLACE TABLE t1 (a TINYTEXT DEFAULT ?)' USING REPEAT('a', 256);
      SHOW CREATE TABLE t1;
      

      +-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | Table | Create Table                                                                                                                                                                                                                                                                                                                                         |
      +-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | t1    | CREATE TABLE `t1` (
        `a` tinytext DEFAULT 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
      +-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      

      The table was created without problems.
      Note, instead EXECUTE IMMEDIATE it can be also a directly executed CREATE statement with an explicit long string literal:

      CREATE OR REPLACE TABLE t1 (a TINYTEXT DEFAULT '...256 or more characters...');
      

      Now if I run any query which sets t1.a to the default value, I get an error:

      INSERT INTO t1 VALUES ();
      

      ERROR 1406 (22001): Data too long for column 'a' at row 1
      

      Looks wrong. Too long literals should be caught at CREATE time, like they are caught in case of VARCHAR:

      CREATE OR REPLACE TABLE t1 (a VARCHAR(10) DEFAULT '...10 or more characters...');
      

      ERROR 1067 (42000): Invalid default value for 'a'
      

      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.