An enumeration (enum) is a data type whose values come from a fixed set of named alternatives. DuckDB stores enum values internally as integers, making them efficient for storage and processing while retaining string-like access. section 1.7.2 section 10.1.7
Create an enum for tags
A tag vocabulary can become an enum and then an enum list: CREATE TYPE tag AS enum (SELECT DISTINCT tagname FROM tags); ALTER TABLE posts ADD tagEnums tag[]; UPDATE posts SET tagEnums = tagNames WHERE posttypeid = 1;. Query membership with list_contains(tagEnums, 'java'). section 10.1.7
Listing 10.15 Creating an enum type for tags from the tags table
CREATE TYPE tag AS enum (SELECT DISTINCT tagname FROM tags);
Create an enum directly from the distinct values in a tags table. section 10.1.7
Useful enum operations include:
- enum_code returns an enum's numeric code. section 10.1.7
- enum_range returns all enum values; enum_first, enum_last, and enum_range_boundary inspect its boundaries. section 10.1.7
- DuckDB automatically casts enums to strings for string functions and comparisons. section 10.1.7






















