By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Help with an interesting Postgres question: Why isn't an Index Only Scan used on a partition accessed via the parent table?.
CREATE FUNCTION is_unique(input text[])
RETURNS bool AS $$
SELECT NOT EXISTS(SELECT 1
FROM unnest(input) AS v(value)
GROUP BY value
HAVING COUNT(*) > 1) AS result;
$$ LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT
LEAKPROOF;
CREATE FUNCTION
CREATE TABLE IF NOT EXISTS test
(
id SERIAL NOT NULL,
component_type text COLLATE pg_catalog."default" NOT NULL,
component_names text[] COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT test_pk PRIMARY KEY (id),
CONSTRAINT uq_names CHECK ( is_unique(component_names) )
)
CREATE TABLE
INSERT INTO test(component_type, component_names)
VALUES ('hello', ARRAY['a', 'b', 'a']);
ERROR: new row for relation "test" violates check constraint "uq_names" DETAIL: Failing row contains (1, hello, {a,b,a}).