This feels like a very basic question, but I really don't see the obvious answer at the moment.
I have a simple table that maps object ids between two namespaces:
|---------------------|------------------|
| id_in_ns1 | id_in_ns2 |
|---------------------|------------------|
| 1 | 5 |
|---------------------|------------------|
| 2 | 17 |
|---------------------|------------------|
| 3 | NULL |
|---------------------|------------------|
| NULL | 1 |
|---------------------|------------------|
The mapping is basically 1:1, but as you can see, some objects from namespace 1 do not exist in namespace 2, and vice versa, so that there are NULL
values in the table.
So, what would be the primary key of this table? As a PK cannot be NULL
, I can neither use (id_in_ns1)
nor (id_in_ns2)
nor the composite.
The only idea I have is to replace NULL
by a definite value, say -1
, and to use (id_in_ns1, id_in_ns2)
as PK. However, this feels not only hackish but also "unnormal" because the non-NULL
(or non--1
)) value alone is already sufficient to uniquely identify an object.