[MDEV-19317] TEXT column accepts too long literals as a default value Created: 2019-04-24  Updated: 2019-04-25  Resolved: 2019-04-25

Status: Closed
Project: MariaDB Server
Component/s: Data types
Affects Version/s: 10.2, 10.3, 10.4
Fix Version/s: 10.4.5

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-4912 Data type plugin API version 1 Closed

 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'


Generated at Thu Feb 08 08:50:45 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.