0

I have a table with several unique indexes. Is it possible to ON CONFLICT UPDATE only on one of them and DO NOTHING on all others, handling with DO NOTHING future unique indexes without going back and modifying code or at least existing ones. Ex:

ON CONFLICT (name, age)
DO UPDATE SET
    occupation = 'teacher'
ELSE ON CONFLICT(all others) DO NOTHING;

Right now, of course, it throws an error for all other indexes besides 1st one. Or alternatively what is the best way to handle it so no errors are thrown. Thank you.

CREATE UNIQUE INDEX index1 ON contact USING btree (name, age);
CREATE UNIQUE INDEX index2 ON contact USING btree (name, address) WHERE (address IS NOT NULL);
CREATE UNIQUE INDEX index3 ...
CREATE UNIQUE INDEX index4 ...

INSERT INTO contact
    (name,
    age,
    address,
    occupation) 
VALUES
    ('John',
    25,
    '1 main st',
    'doctor')
ON CONFLICT (name, age)
DO UPDATE SET
    occupation = 'teacher';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.