postgres 新增或者更新语句


INSERT INTO _fba_inventory (asin, store_id, total_qty)
VALUES (2, 2, 1)
ON CONFLICT (asin,store_id) DO UPDATE SET total_qty = 4,
                                          write_date=now();

-- 发现冲突后什么也不处理
INSERT INTO _fba_inventory (asin, store_id, total_qty)
VALUES (2, 2, 1)
ON CONFLICT (asin,store_id) DO nothing ;

-- 将插入的值+5 用来更新
INSERT INTO starmerx_fba_inventory (asin, store_id, total_qty)
VALUES (2, 2, 1)
ON CONFLICT (asin,store_id) DO UPDATE SET total_qty = excluded.total_qty+4,
                                          write_date=now();

-- 更新:在原有的基础上+4
INSERT INTO _fba_inventory (asin, store_id, total_qty)
VALUES (2, 2, 1)
ON CONFLICT (asin,store_id) DO UPDATE SET _fba_inventory.total_qty = 4,
                                          write_date=now();
原文地址:https://www.cnblogs.com/qianxunman/p/14201930.html