かなり昔、
oboe2uran.hatenablog.com
を書いた。
constraint を書かない時の UPSERT、Primary Key しか書いていない時の
UPSERT の書き方は、
前回の投稿のテーブルで、id が Primary Keyである場合、、、
前回の投稿
INSERT INTO sample (id, `point`, price) VALUES (3, 40, 400) ON CONFLICT ON CONSTRAINT sample_pkey DO UPDATE SET point = 40, price = 400
constraint を書かない時
INSERT INTO sample (id, `point`, price) VALUES (3, 40, 400) ON CONFLICT (id) DO UPDATE SET point = 40, price = 400
となる。
複数列で、Primary Key なら、カンマ区切りで並べる。