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