I have a table that has two columns that are unique, and would like to upsert if the first column (or both columns) has a conflict, but do nothing if only the second column has a conflict. Is this possible?
CREATE TABLE test (
username VARCHAR(255) NOT NULL UNIQUE,
email VARCHAR(255) NOT NULL UNIQUE,
status VARCHAR(127)
);
The following works to check for conflicts on email:
INSERT INTO test(username, email)
VALUES ('test', 'test@test.test')
ON CONFLICT(email) DO UPDATE SET status='upserted';
But I'd like to do something like this (invalid syntax below):
(INSERT INTO test(username, email)
VALUES ('test', 'test@test.test')
ON CONFLICT(email) DO UPDATE SET status='upserted')
ON CONFLICT DO NOTHING;