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?
-999999)dwould be the price anda, b, cwould be meta information and would stand for a unique identifier for the price. If I insert [a='US', b=NULL, c='USD', d=1000], I want this price to be updated if I insert [a='US', b=NULL, c='USD', d=500] later. So I can't put the unique constraint ona, b, c, d. @a_horse_with_no_name Indeed there are values which will never appear. However I think it's much cleaner to keep NULL for data which are meant to be unfilled instead of putting a custom predefined value?