小编Ken*_*n D的帖子

postgreSQL 更新仅在可以强制转换的情况下设置并忽略错误?

我在 PostgreSQL 表中有 2 列。该mac_address_temp列用于从字符类型迁移到 MAC 地址类型:

mac_address      | macaddr               |
mac_address_temp | character varying(17) |
Run Code Online (Sandbox Code Playgroud)

我想将数据从 mac_address_temp 迁移到 mac_address,但有些数据无法转换为macaddr类型。

mac_address | mac_address_temp
-------------+------------------
            | AAB5:4f27:e299
            | AAB54f27e299

UPDATE mactable SET mac_address = CAST(mac_address_temp as macaddr);
ERROR:  invalid input syntax for type macaddr: "AAB5:4f27:e299"
Run Code Online (Sandbox Code Playgroud)

有没有办法忽略CAST不工作的地方并仍然更新表格的其余部分?

postgresql update

4
推荐指数
1
解决办法
4929
查看次数

标签 统计

postgresql ×1

update ×1