1. 3
  1.  

  2. 5

    I’ve been dabbling in SQL for well over 2 decades now (personally and professionally) and this is the first I’ve heard of ENUMs in MySQL.

    I agree with the linked post, they don’t seem to add that much value compared to reference tables.

    Also the “obvious” binary choice example “male/female” used in the post is feeling really dated (article is from 2011). How time flies!

    1. 4

      I’m not familiar enough with MySQL to comment on this but it’s simply not true for Postgres.

      The representation in Postgres is a 4 byte integer, and using an enum saves you a join which over a large result set may be expensive (often due to a poorly written query but there’s still no reason to set traps for yourself).

      Adding additional information to an enum is simple - have a table with an enum value as the primary key.

      Postgres provides functions to retrieve the values of an enum. Removing values is expensive, but that’s going to be true whether or not you’re using an enum or a key to your fake enum table.

      Looking at the MySQL docs, it seems like the same advantages apply: https://dev.mysql.com/doc/refman/8.0/en/enum.html

      1. 3

        I’ve never really understood why ENUM types exist in SQL databases, when tables and referential integrity are right there.