Updated on 2025-10-23 GMT+08:00

Character Types

Table 1 lists the character types supported by M-compatible databases.

Table 1 Character Types

Name

Description

Storage Space

CHAR[(n)]

Fixed-length character string. Empty characters are filled in with blank spaces. n indicates the string length. If it is not specified, the default precision 1 is used.

Up to 255 characters

VARCHAR(n)

Variable-length character string. n indicates the string length.

Up to 65532 bytes

TEXT[(n)]

Variable-length character string. n indicates the optional string length of the type. After n is specified, a column is created as the TEXT type that has the minimum length but is sufficient to hold the byte length corresponding to n characters.

Up to 65535 bytes

TINYTEXT

Variable-length character string.

Up to 255 bytes

MEDIUMTEXT

Variable-length character string.

Up to 16777215 bytes

LONGTEXT

Variable-length character string.

Up to 1 GB minus 1 byte

  • If the value of sql_mode contains strict_trans_tables and the input value is invalid or exceeds the storage space range, an ERROR message is reported.
  • If the value of sql_mode does not contain strict_trans_tables and the input value is invalid or exceeds the storage space range, the truncated value is returned.
  • If the value of sql_mode contains pad_char_to_full_length and table columns and temporary variables are of the CHAR type, the character string with trailing spaces is output. If the value of sql_mode does not contain pad_char_to_full_length and table columns and temporary variables are of the CHAR type, the character string with no trailing spaces is output.
  • The '||' connector is not supported.

Examples

Character types are displayed using character strings.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
-- Create a table with data of the CHAR type.
m_db=# CREATE TABLE text_type_t1  
(
    BT_COL1 CHAR(10)
);

-- Insert data.
m_db=# INSERT INTO text_type_t1 VALUES ('text_test1');

-- Query data in the table.
m_db=# SELECT *  FROM text_type_t1;
  BT_COL1
------------
 text_test1
(1 row)

-- Drop the table.
m_db=# DROP TABLE text_type_t1;

-- Create a table with data of the VARCHAR type.
m_db=# CREATE TABLE text_type_t2  
(
    BT_COL2 VARCHAR(10)
);

-- Insert data.
m_db=# INSERT INTO text_type_t2 VALUES ('text_test2');

-- Query data in the table.
m_db=# SELECT *  FROM text_type_t2;
  BT_COL2
------------
 text_test2
(1 row)

-- Drop the table.
m_db=# DROP TABLE text_type_t2;

-- Create a table with data of the TEXT type.
m_db=# CREATE TABLE text_type_t3  
(
    BT_COL3 TEXT
);

-- Insert data.
m_db=# INSERT INTO text_type_t3 VALUES ('text_test3');

-- Query data in the table.
m_db=# SELECT *  FROM text_type_t3;
  BT_COL3
------------
 text_test3
(1 row)

-- Drop the table.
m_db=# DROP TABLE text_type_t3;

-- Example: CHAR type.
-- Create a table.
m_db=# CREATE TABLE char_type_t1  
(
    BT_COL1 CHAR(5)
);

-- With the strict mode enabled, an error is reported if the length of an inserted string exceeds the length specified for the type.
m_db=# SET SQL_MODE = 'strict_trans_tables,only_full_group_by,no_zero_in_date,no_zero_date,error_for_division_by_zero,
no_auto_create_user,no_engine_substitution';
SET
m_db=# INSERT INTO char_type_t1 VALUES ('too long');
ERROR:  value too long for type character(5)
CONTEXT:  referenced column: BT_COL1

-- With the strict mode disabled, a warning message is reported and the value is truncated if the length of an inserted string exceeds the length specified for the type.
m_db=# SET SQL_MODE = '';
SET
m_db=# INSERT INTO char_type_t1 VALUES ('too long');
WARNING:  value too long for type character(5)
CONTEXT:  referenced column: BT_COL1
INSERT 0 1

-- Query data in the table.
m_db=# SELECT * FROM char_type_t1;
m_db=# SELECT * FROM char_type_t1;
 BT_COL1
---------
 too l
(1 row)

-- Drop the table.
m_db=# DROP TABLE char_type_t1;