繁体   English   中英

PostgreSQL更新同一表中的另一列

[英]PostgreSQL update column from another column in same table

该表称为人工。 我有一列称为code的代码,其中包含数百个代码,但代码仅以1、2或4开头。我试图更新同一表中的新列,其中包含每个代码的第一位数字。

 existing column  column to update(exists but is empty)
 code             type_
 113249            1
 135435            1   
 254646            2
 208984            2
 409098            4
 429540            4

代码列是数字列,而type_列也是数字列

这是我尝试过的但没有奏效的

update labor set type_ = case code
            when code::text like '%1' then 1 
            when code::text like '%2' then 2
            when code::text like '%4' then 4
            end
update labor set type_ = left(code::text, 1)::int8

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM