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?
@veronica Iβm not sure I am parsing correctly your question; you have a table with (at least) three columns id, date and name. You have the constraint that each tuple (id, date) is unique (but you may have duplicate ids, and duplicate dates). And you want to add a constraint such that for any "name" value, all the rows having that name have the same id?
@immae Since the object represented by the ID can be renamed, which triggers an INSERT with a new version rather than an UPDATE, joint tables get a little messy, but yeah, it's my last resort solution.
@veronica So you want that no two objects can have the same name, which seems reasonnable. But also with your hypothetical constraint, if you have two objects named 'a' and 'b', when you rename 'a' to 'c', then you cannot rename 'b' to 'a' (since otherwise your constraint would fail), is that reasonnable too?
@veronica (There "may" be a solution with one table, I just donβt see it and it seems much easier to tackle with two tables, hence the question)