现在的需求是将model中的字符拆分,找出数字,并更新到v_cpu的字段上,更新的逻辑是
1、先拆分
SELECT ID, string_to_array( fastone_model, '.' ) AS model FROM reserved_instance
2、再打成行的形式
SELECT ID, UNNEST ( string_to_array( fastone_model, '.' ) ) AS model FROM reserved_instance
3、过滤掉字符的行
SELECT
ri.model AS bmodel,
ri.ID AS bid
FROM
( SELECT ID, UNNEST ( string_to_array( fastone_model, '.' ) ) AS model FROM reserved_instance ) ri
WHERE
ri.model ~ '^[^a-z]+$'
4、更新到新的字段
UPDATE reserved_instance
SET v_cpu = b.bmodel :: INT
FROM
(
SELECT
ri.model AS bmodel,
ri.ID AS bid
FROM
( SELECT ID, UNNEST ( string_to_array( fastone_model, '.' ) ) AS model FROM reserved_instance ) ri
WHERE
ri.model ~ '^[^a-z]+$'
) b
WHERE
b.bid = ID
5、查看是否更新成功
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/sunyuhua_keyboard/article/details/121163043
内容来源于网络,如有侵权,请联系作者删除!