Issues with UniqueColumns constraints with nullable fields #457
-
Maybe I have understood something wrong. I have added the following constraints into my model:
In my understand, it will restrict me to have two entries where ALL 5 columns are equal. But to my surprise:
Both are exactly the same. And these are the restriction in Postgres
Created by these
My questions are:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I found out the solution: Postgres cannot handle unique constrains with Nullable fields since A possible solution is to create partial indexes, without the nullable fields, but that is impractical with 4 them because I would need a 4! - 4 constraints. Another alternative is to use COALESCE. I think I will find out another solution. |
Beta Was this translation helpful? Give feedback.
I found out the solution:
Postgres cannot handle unique constrains with Nullable fields since
Null != Null
. As explained ins this SO post.A possible solution is to create partial indexes, without the nullable fields, but that is impractical with 4 them because I would need a 4! - 4 constraints.
Another alternative is to use COALESCE. I think I will find out another solution.