Any database wizards out there?

I have a table with an ID column. The ID column is unique together with a valid date, so the ID itself is not unique.

However, I also need a name column that is unique under the condition that any given name can only correspond to one specific ID (but not necessarily the other way around).

The database is PostgreSQL. Is it possible to formulate, for instance, a UNIQUE INDEX to achieve this?

Edit: Solved 🥳

#Programming #Development #Help #Database #PostgreSQL

Follow

@veronica a partial unique index might do what you want, or get you close.

But it might be worth asking is the data model sensible.

@intrbiz The data model is what it is, and not under my control, so let's leave it at that 😅

But an EXCLUDE constraint seems to have solved the problem: mastodon.online/@veronica/1145

Sign in to participate in the conversation
Mastodon

Time for a cuppa... Earl Grey please!