I want to emulate the following insert statement (listed
here) in jOOQ :
INSERT INTO key_value_pair (key, value, is_active) VALUES ('temperature','20', false)
ON CONFLICT (key) WHERE is_active
DO UPDATE
SET value = '33', is_active = true;
To do this, I am writing the following code :
dslContext.insertInto(KEY_VALUE_PAIR).columns(KEY_VALUE_PAIR.KEY, KEY_VALUE_PAIR.VALUE, KEY_VALUE_PAIR.IS_ACTIVE)
.values("temperature", "20", false)
.onConflict(KEY_VALUE_PAIR.KEY, KEY_VALUE_PAIR.VALUE, KEY_VALUE_PAIR.IS_ACTIVE).doNothing().execute();
but, it fails with the following error :
nested exception is org.postgresql.util.PSQLException: ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
The partial index that I am using is :
CREATE INDEX key_and_value_if_is_active_true_unique ON key_value_pair (key, value) WHERE is_active = true;
The question is : I think jOOQ does not support the WHERE index predicate in the onConflict clause. Is there a workaround for this?