I want to have a case-insensitive unique key on a large table.
I'm looking for the fastest approach.
I found two options: my_table_a with a generated column and my_table_b with a unique index
CREATE TABLE my_table_a
(
my_table_id_a int GENERATED ALWAYS AS IDENTITY
CONSTRAINT pk_my_table_a PRIMARY KEY,
name text NOT NULL,
key text GENERATED ALWAYS AS (LOWER(name)::text) STORED NOT NULL
);
CREATE TABLE my_table_b
(
my_table_id_b int GENERATED ALWAYS AS IDENTITY
CONSTRAINT pk_my_table_b PRIMARY KEY,
name text NOT NULL
);
CREATE UNIQUE INDEX unique_name ON my_table_b (LOWER(name));
But I'm not sure what is happening on an insert. I fear that for a single insert, it is required to calculate for all rows the unique key.
What do you think is the fastest solution?