// data type reference

ENUM and enumerated types

PostgreSQL puts the value list in a schema type, MySQL puts it on the column, Oracle 23ai has enum domains, and SQL Server and SQLite make you use a CHECK constraint or lookup table.

Missing in
SQL Server, SQLite
Gotchas
5 listed

Engine by engine

A real enum type (PostgreSQL) is ordered and schema-wide; MySQL ENUM is declared per column and sorts by position; the rest fake it with CHECK constraints, which edit differently.

ENUM in SQL Server, PostgreSQL, MySQL, SQLite and Oracle: type name, storage and notes
Engine Typ Speicher Notizen
SQL Server none (CHECK or lookup table) Workaround k.A. No enum type. A CHECK (status IN ('new','paid')) or a lookup table with a foreign key; lookup tables are the standard answer when values carry data.
PostgreSQL ENUM (CREATE TYPE) 4 bytes CREATE TYPE mood AS ENUM ('sad','ok','happy'): stored as an int index, ordered by declaration, labels are case-sensitive and shared schema-wide.
MySQL ENUM('a','b','c') 1-2 bytes Declared on the column inside CREATE TABLE; stored as a 1- or 2-byte index into the value list, sorted by that index, not alphabetically.
SQLite none (TEXT + CHECK) Workaround TEXT size No enum. TEXT with CHECK (col IN (...)) is the idiom; nothing but the constraint ties the value list down.
Oracle enum domain (23ai) or CHECK k.A. 23ai adds CREATE DOMAIN ... AS ENUM; earlier releases use CHECK constraints or lookup tables.

Gotchas

Where the engines disagree. These tend to surface as bugs during a migration or a port.

  1. MySQL ENUM sorts by declaration order, not alphabetically: ORDER BY on an ENUM column returns the values in the order they were listed in CREATE TABLE, which is either a feature or a bug depending on who wrote the query.
  2. MySQL also stores the empty string '' for invalid values when strict mode is off, silently: the row inserts with a value that is not in your list.
  3. PostgreSQL enums grow awkwardly: ALTER TYPE ... ADD VALUE appends (or goes BEFORE/AFTER an existing label), RENAME VALUE works since 10, but removing or reordering means creating a new type and rewriting the column.
  4. CHECK-constraint enums (SQL Server, SQLite, Oracle) edit with ALTER TABLE, but the value list is duplicated everywhere the column appears across the schema.
  5. PostgreSQL enum labels are case-sensitive and typed: mood_col = 'happy' works because the literal is coerced, but mood_col = some_text_column fails with 'operator does not exist: mood = text' until you cast.

Common questions

MySQL ENUM or a lookup table?

Lookup table when values may change, carry extra data, or are referenced across tables; ENUM only for a short list that never changes, where you accept an ALTER TABLE to add a value.

How do I add a value to a PostgreSQL enum?

ALTER TYPE mytype ADD VALUE 'new' (optionally BEFORE or AFTER an existing label). Before PostgreSQL 12 it could not run inside a transaction block; since 12 it can, but the new value is unusable until that transaction commits. There is no DROP VALUE.

Why does my enum column sort weirdly?

MySQL ENUMs and PostgreSQL enums both sort by their position in the declared list, not alphabetically. CHECK-constraint text columns sort alphabetically, because they are just text.

// map types before you move data

Map a type to the other four engines

The free type converter maps a type from one engine to its closest equivalent in the others and says where storage, precision or behaviour differ. The desktop app does the same mapping while you edit.