PostgreSQL convert column from inet to text

2019-07-24 17:15发布

I'd like to change type of column from inet to text. So, I execute:

ALTER TABLE table ALTER COLUMN col TYPE text;

But then I found out that for all values was added mask. For example: 192.168.100.141 -> 192.168.100.141/32. Is it possible to change inet column to text without any changes in this column?

1条回答
聊天终结者
2楼-- · 2019-07-24 17:56

Use host() to extract just the ip address:

ALTER TABLE table ALTER COLUMN col TYPE text USING host(col);
查看更多
登录 后发表回答