Updated on 2025-09-09 GMT+08:00

String Data Types

Table 1 String Data Types

Data Type

Differences Compared with MySQL

CHAR(M)

For details about the differences, see the note below the table.

VARCHAR(M)

For details about the differences, see the note below the table.

TINYTEXT

For details about the differences, see the note below the table.

TEXT

For details about the differences, see the note below the table.

MEDIUMTEXT

For details about the differences, see the note below the table.

LONGTEXT

Input format:
  • GaussDB supports a maximum of 1 GB – 512 bytes, and MySQL supports a maximum of 4 GB – 1 byte.
  • For other differences, see the note below the table.
  • For binary or hexadecimal strings that cannot be escaped, MySQL outputs an empty string, while GaussDB outputs a hexadecimal result.
  • For the TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT types:
    • The default value cannot be set in MySQL 5.7 but can be set in GaussDB and MySQL 8.0.
    • Primary key: When creating a primary key, you must specify the prefix length in MySQL, but you cannot specify the prefix length in GaussDB.
    • Index: MySQL supports only prefix indexes. GaussDB supports all index methods.
    • Foreign key: MySQL does not support any of these types to be the referencing column or referenced column of a foreign key, but GaussDB supports.

Example:

-- GaussDB
m_db=# CREATE TABLE test_text(a text);
CREATE TABLE

m_db=# INSERT INTO test_text VALUES(0x1);
INSERT 0 1

m_db=# INSERT INTO test_text VALUES(0x111111);
INSERT 0 1

m_db=# INSERT INTO test_text VALUES(0x61);
INSERT 0 1

m_db=# SELECT * FROM test_text;
      a       
--------------
 \x01
 \x11\x11\x11
 a
(3 rows)

m_db=# DROP TABLE test_text;
DROP TABLE

-- MySQL 5.7
mysql> CREATE TABLE test_text(a text);
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO test_text VALUES(0x1);
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO test_text VALUES(0x111111);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO test_text VALUES(0x61);
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM test_text;
+------+
| a    |
+------+
|     |
|   |
| a    |
+------+
3 rows in set (0.00 sec)

mysql> DROP TABLE test_text;
Query OK, 0 rows affected (0.01 sec)