Skip to main content

Enum type

The ENUM type is a string object that can have only one value, which must be one of the values in the list 'value1', 'value2', ... . The enum values must be quoted string literals.

Internally, ENUM values are represented as integers. A single ENUM column can contain up to 65,535 different elements (the actual limit is less than 3,000). ENUM is a variable-length type that supports the UTF8MB4 character set.

The syntax of ENUM is as follows:

ENUM('value1','value2',...) [CHARACTER SET charset_name] [COLLATE collation_name]

The CHARACTER SET clause specifies the character set. You can use the COLLATE attribute and other attributes to specify the collation of the character set, if needed.

The ENUM type has the following advantages:

  • Input strings are automatically encoded as numbers, which compresses data storage.

  • Queries and outputs are readable. Numbers are converted back to the corresponding strings in the query results.