64 lines
3.2 KiB
Markdown
64 lines
3.2 KiB
Markdown
---
|
|
|
|
slug: /text
|
|
---
|
|
|
|
# TEXT types
|
|
|
|
The `TEXT` type is used to store all types of text data.
|
|
|
|
There are four text types: `TINYTEXT`, `TEXT`, `MEDIUMTEXT`, and `LONGTEXT`. They correspond to the four `BLOB` types and have the same maximum length and storage requirements.
|
|
|
|
`TEXT` values are treated as non-binary strings. They have a character set other than binary, and values are sorted and compared according to the collation rules of the character set.
|
|
|
|
When strict SQL mode is not enabled, if a value assigned to a `TEXT` column exceeds the column's maximum length, the portion that exceeds the length is truncated and a warning is generated. When using strict SQL mode, an error occurs (rather than a warning) if non-space characters are truncated, and the value insertion is prohibited. Regardless of the SQL mode, truncating excess trailing spaces from values inserted into `TEXT` columns always generates a warning.
|
|
|
|
## TINYTEXT
|
|
|
|
`TINYTEXT` is a `TEXT` type with a maximum length of 255 bytes.
|
|
|
|
`TINYTEXT` syntax:
|
|
|
|
```sql
|
|
TINYTEXT [CHARACTER SET charset_name] [COLLATE collation_name]
|
|
```
|
|
|
|
`CHARACTER SET` is used to specify the character set. If needed, you can use the `COLLATE` attribute along with other attributes to specify the collation rules for the character set. If the binary attribute of `CHARACTER SET` is specified, the column will be created as the corresponding binary string data type, and `TEXT` becomes `BLOB`.
|
|
|
|
## TEXT
|
|
|
|
The maximum length of a `TEXT` column is 65,535 bytes.
|
|
|
|
An optional length `M` can be specified for the `TEXT` type. Syntax:
|
|
|
|
```sql
|
|
TEXT[(M)] [CHARACTER SET charset_name] [COLLATE collation_name]
|
|
```
|
|
|
|
`CHARACTER SET` is used to specify the character set. If needed, you can use the `COLLATE` attribute along with other attributes to specify the collation rules for the character set. If the binary attribute of `CHARACTER SET` is specified, the column will be created as the corresponding binary string data type, and `TEXT` becomes `BLOB`.
|
|
|
|
## MEDIUMTEXT
|
|
|
|
`MEDIUMTEXT` is a `TEXT` type with a maximum length of 16,777,215 bytes.
|
|
|
|
`MEDIUMTEXT` syntax:
|
|
|
|
```sql
|
|
MEDIUMTEXT [CHARACTER SET charset_name] [COLLATE collation_name]
|
|
```
|
|
|
|
`CHARACTER SET` is used to specify the character set. If needed, you can use the `COLLATE` attribute along with other attributes to specify the collation rules for the character set. If the binary attribute of `CHARACTER SET` is specified, the column will be created as the corresponding binary string data type, and `TEXT` becomes `BLOB`.
|
|
|
|
Additionally, seekdb also supports the extended type `LONG`, but `MEDIUMTEXT` is recommended.
|
|
|
|
## LONGTEXT
|
|
|
|
`LONGTEXT` is a `TEXT` type with a maximum length of 536,870,910 bytes. The effective maximum length of a `LONGTEXT` column also depends on the maximum packet size configured in the client/server protocol and available memory.
|
|
|
|
`LONGTEXT` syntax:
|
|
|
|
```sql
|
|
LONGTEXT [CHARACTER SET charset_name] [COLLATE collation_name]
|
|
```
|
|
|
|
`CHARACTER SET` is used to specify the character set. If needed, you can use the `COLLATE` attribute along with other attributes to specify the collation rules for the character set. If the binary attribute of `CHARACTER SET` is specified, the column will be created as the corresponding binary string data type, and `TEXT` becomes `BLOB`. |