Suppose, I have the following table:
CREATE TABLE "user" (
id BIGINT PRIMARY KEY NOT NULL,
phone1 VARCHAR,
phone2 VARCHAR
);
And I need to implement the following limitation: all phone numbers (if any) in table must be unique.
i.e database should not allow any of the following situations:
id | phone1 | phone2
1 | 111 | 111
id | phone1 | phone2
1 | 111 | NULL
2 | 111 | NULL
id | phone1 | phone2
1 | 111 | NULL
2 | NULL | 111
I know how to implement constraints for first two examples, but I'm stuck with the third one. Is there any way to do this?