Skip to main content
1 of 3

Convert varchar column to inet in PostgreSQL

I have a table column containing IP addresses, datatype is VARCHAR(255). I want to switch to inet datatype now. Is there a way to convert existing addresses in IP column to inet datatype? Tried:

ALTER TABLE request_logs ALTER COLUMN ip type inet USING ip::inet;
ALTER TABLE request_logs ALTER COLUMN ip type inet USING CAST(ip AS inet);

But no luck, getting PG::DatatypeMismatch: ERROR: default for column "sign_up_ip" cannot be cast automatically to type inet.