3 ms·
No, the constraint can require exactly one column. PostgreSQL even has an optimized builtin function for this, `num_nonnulls`. In a recent feature I had an obj
by piaste 5y ago
No, the constraint can require exactly one column. PostgreSQL even has an optimized builtin function for this, `num_nonnulls`.
In a recent feature I had an object field modelled as:
type Destination = Customer of Customer | Supplier of Supplier | Warehouse of Warehouse
and the table representation was
customer_id uuid null
, supplier_id uuid null
, warehouse_id uuid null
, constraint unique_destination check (num_nonnulls(customer_id, supplier_id, warehouse_id) = 1)
It's not first class support, but manageable enough.