You can use the function in a check constraint:
create or replace function array_is_unique(arr anyarray)
returns boolean language sql immutable as
$$
select count(distinct a) = array_length(arr, 1)
from unnest(arr) a
$$;
Example usage:
create type notification as enum ('a', 'b', 'c');
create table my_table(
id serial primary key,
notifications notification[] check(array_is_unique(notifications))
);
Is there a way to set this data type?
You can create a domain, example:
create domain notifications as notification[] check(array_is_unique(value));
drop table if exists my_table;
create table my_table(
id serial primary key,
notifications notifications
);
insert into my_table (notifications)
values ('{a, a}');
ERROR: value for domain notifications violates check constraint "notifications_check"