Due to enum inheritance restrictions (you cannot add values ββto an enumeration from inside the function), I go to user domains with a check constraint checking the values. I need to create arrays of my custom enums, but when I try something like this:
CREATE DOMAIN foo AS text CHECK (VALUE IN ('foo', 'bar')); CREATE TABLE foo_table(foo_column foo[]);
I get an error
type "foo[]" does not exist
Performing some searches, I found this since 2004 , which made it look like support for this. Is there any way to do this?
Thanks!
UPDATE
I came up with a hacker solution, which I will answer if in a few days no one finds a better solution. This solution means you cannot reuse the type to be an array, you need to create a separate type that acts like an array:
CREATE DOMAIN foo_group AS text[] CHECK (VALUE <@ ARRAY['foo', 'bar']); CREATE TABLE foo_table(foo_column foo_group);
Next job:
INSERT INTO foo_table VALUES(ARRAY['foo']); INSERT INTO foo_table VALUES(ARRAY['foo', 'bar']); INSERT INTO foo_table VALUES(ARRAY['bar']);
It does not follow:
INSERT INTO foo_table VALUES(ARRAY['foo', 'baz']); INSERT INTO foo_table VALUES(ARRAY['baz']);
source share