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();


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM