PostgreSQL convert column from inet to text

别来无恙 提交于 2019-12-23 23:31:25

问题


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:


Use host() to extract just the ip address:

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


来源:https://stackoverflow.com/questions/29101458/postgresql-convert-column-from-inet-to-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!