Let's say I have a table with several columns [a, b, c, d]
which can all be nullable. This table is managed with Typeorm.
I want to create a unique constraint on [a, b, c]
. However this constraint does not work if one of these column is NULL. I can insert for instance [a=0, b= 1, c=NULL, d=0]
and [a=0, b= 1, c=NULL, d=1]
, where d
has different values.
With raw SQL, I could set multiple partial constraints (Create unique constraint with null columns) however, in my case, the unique constraint is on 10 columns. It seems absurd to set a constraint for every possible combination...
I could also create a sort of hash function, but this method does not seem proper to me?
Does Typeorm provide a solution for such cases?