I want to define a PostgreSQL table like below:
create table contacts (
first_name varchar,
last_name varchar,
phone_numbers varchar[]
);
However, I want to set a limit for phone_numbers
so that the user cannot insert data more than that limit.
CodePudding user response:
Use a check constraint:
create table contacts (
first_name varchar,
last_name varchar,
phone_numbers varchar[],
constraint limit_phone_numbers
check (cardinality(phone_numbers) <= 5)
);