create table sample
(index integer not null,
name text not null,
age integer not null);
alter table sample add constraint sample_key primary key(index, name);
データとして、下記が存在している状態で。
index | name | age
-------+----------+-----
1 | hogehoge | 19
2 | fugafuga | 20
3 | piyopuyo | 21
下記を実行すると。
insert into sample
(index, name, age)
values
(1, 'hogehoge', 23)
on conflict
(index, name)
do update set age = 23;
下記の状態になりました。
index | name | age
-------+----------+-----
2 | fugafuga | 20
3 | piyopuyo | 21
1 | hogehoge | 23