Because of the inherit limitations of enum (you can\'t add values to the enum from within a function), I\'m switching to custom domains with a check constraint verifying the
Another possible workaround is:
CREATE TYPE foo_tup AS (item foo);
Domain types can wrapped in tuples like this and that gives you an array constructor. The downside is now you probably want to create casts:
select array[row('foo')::foo_tup, row('bar')];
For example you could create a function and a cast:
create function foo_tup(foo) returns foo_tup language sql as $$
select row($1)::foo_tup;
$$ immutable;
create function foo(foo_tup) returns foo language sql as $$
select $1.item;
$$;
create cast (foo as foo_tup) with function foo_tup(foo);
create cast (foo_tup as foo) with function foo(foo_tup);
Then aggregation becomes easy:
select array_agg(myfoo::foo_tup) from my_table;
though you get extra parentheses.