Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the maximum length for an ENUM value?

Tags:

types

enums

mysql

Searched the docs, but to no avail.
What is the maximum length for an enumeration value, i.e. the string literal?

like image 237
Eugene Yarmash Avatar asked Nov 29 '10 19:11

Eugene Yarmash


1 Answers

The limit isn't on the length of the literal string, but rather on the table definition.

The MySQL documentation states that

Each table has an .frm file that contains the table definition. The server uses the following expression to check some of the table information stored in the file against upper limit of 64KB.

which is then followed by an ad-hoc equation expressing the approximate size of a table definition.

For a simple test, in a table with a couple fields already, I got my enum up to 63136 characters long, and the .frm was 71775 bytes big (slightly larger than 70KB), so the limit is approximate. At that point, MySQL complained #1117 - Too many columns, which is misleading to say the least.

Interestingly/oddly/worthwhile to note, the character set of the enum will change the maximum length. -- even if you're using normal characters which should only require 1 byte each.

like image 188
Riedsio Avatar answered Sep 19 '22 08:09

Riedsio