0

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.

1 Answer 1

4

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)
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.