postgres 批量更新內容


在程序中遇到這樣的需求, 數據庫表格式如下

需要把批量更新status, 如name = fox 時, status = 1, name = boa 時,status = 2 .... 類似的

postgres 的寫法如下:

update 表名 set status = case name 
        when 'dodo' then '1'  
        when 'eel' then '1' 
       end 
     where name in('dodo', 'eel');
        

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM