0

I have a table that contains the name and date columns. I want to block the insertion of a repeated combination. For example, if I have a record with {name: "joe", date: "2021-05-24"} I need to not allow the insertion of another record {name: "joe", date: "2021-05-24"}. Do exists a simple way to do this in PosgresSQL?

Initially I thought of a dynamic concatenator that would create a string for a column that would be responsible for this validation but I imagine that there is something more elegant.

2
  • So you want to allow joes with other dates? And other people on the same date? Commented May 24, 2021 at 12:39
  • @Bergi yes. I want this Commented May 24, 2021 at 13:02

1 Answer 1

1

You're looking for a multi-column UNIQUE index (or primary key, which uses the same thing underneath). No need for concatenation.

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.