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

TEXT column accepts too long literals as a default value

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 10.2, 10.3, 10.4
    • Fix Version/s: 10.4.5
    • Component/s: Data types
    • Labels:
      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

              • Assignee:
                bar Alexander Barkov
                Reporter:
                bar Alexander Barkov
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: