I have a key-value table.
CREATE TABLE keyvalues (
key TEXT NOT NULL,
value TEXT
)
I want to impose a constraint that if a key has an entry with NULL value, it cannot have any other entries. How do I do that?
To clarify: I want to allow ("key1", "value1"), ("key1", "value2"). But if I have ("key2", NULL), I want to not allow ("key2", "value3").
You can use a trigger, like this:
Then you create the trigger on the table
And test it:
OK
OK
OK
ERROR: Key-value not allowed