An enum array is an ordered collection whose elements use an enum data type. It replaces awkward delimited tag strings with typed values that support list operations and enum functions. section 10.1.7
A practical conversion workflow creates the enum from known tag values, splits the original string into a string array, adds an enum-array column, and assigns the string array to it. DuckDB performs the cast automatically. section 10.1.7
Create and query an enum array
CREATE TYPE tag AS enum (SELECT DISTINCT tagname FROM tags); ALTER TABLE posts ADD tagEnums tag[]; UPDATE posts SET tagEnums = tagNames WHERE posttypeid = 1; SELECT count(*) FROM posts WHERE posttypeid = 1 AND list_contains(tagEnums, 'java'); For aggregations, unnest(tagEnums), group by the resulting tag, and order by the aggregate. 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 the tag enum directly from distinct values in the tags table. section 10.1.7
Listing 10.23 Counting posts with the java tag, using list_contains on the enum list
select count(*) from posts where postTypeId=1 and list_contains(tagEnums, 'java');
Use list_contains to count rows containing a particular enum value. section 10.1.7
