假设我有一张这样的桌子:
CREATE TABLE test (id SERIAL, first VARCHAR(10), second VARCHAR(10), other VARCHAR(10));
CREATE UNIQUE INDEX unique_index ON test (first, second);
INSERT INTO test (first, second, other)
VALUES ('lorem', null, 'old');
INSERT INTO test (first, second, other)
VALUES ('lorem', null, 'new')
ON CONFLICT (first, second)
DO UPDATE SET
other = EXCLUDED.other;
1 lorem (null) old
2 lorem (null) new