gpt4 book ai didi

PostgreSQL 将列从 inet 转换为文本

转载 作者:行者123 更新时间:2023-11-29 11:59:50 24 4
gpt4 key购买 nike

我想将列的类型从 inet 更改为 text。所以,我执行:

ALTER TABLE table ALTER COLUMN col TYPE text;

但后来我发现所有值都添加了掩码。例如:192.168.100.141 -> 192.168.100.141/32。是否可以将 inet 列更改为 text 而无需对此列进行任何更改?

最佳答案

使用host()仅提取 IP 地址:

ALTER TABLE table ALTER COLUMN col TYPE text USING host(col);

关于PostgreSQL 将列从 inet 转换为文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29101458/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com