I would like to create a unique PostgreSQL index that contains operations. Does anyone know if this is possible?
CREATE UNIQUE INDEX ux_data ON table (name, color)
The operation that I would like to add is "num & new_num = 0", where num is an existing column and new_num is a value to be inserted.
Is this possible?
Update: Here's more detail regarding what I want to do.
Database:
name color num
one red 5
two green 5
one red 8
What I want to do is to prevent the case where an entry is not unique, like:
New entry 1: name = one, color = red, num = 1.
We have matching names and colors and the first num check results in 101 & 001 = 1, this New entry 1 is not unique, and should be rejected, however, if the number was changed to 2.
New entry 2: name = one, color = red, num = 2
Now we have matching names and colors. For the num in all name/color matches 101 & 010 = 0, and 1000 & 0010 = 0, so we have a unique entry.