PostgreSQL convert column from inet to text

2019-07-24 17:32发布

问题:

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);