Skip to main content
Tweeted twitter.com/StackDBAs/status/1027072153898950657
include info from comment
Source Link
Erwin Brandstetter
  • 182.1k
  • 28
  • 457
  • 620

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

All values are '127.0.0.1'. Postgres version is 9.6.9.

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

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

All values are '127.0.0.1'. Postgres version is 9.6.9.

tags, format
Source Link
Erwin Brandstetter
  • 182.1k
  • 28
  • 457
  • 620

Convert varchar column to inet in PostgreSQL

I have a table column containing IP addresses, datatype is VARCHAR(255)varchar(255). I want to switch to inetinet datatype now. Is there a way to convert existing addresses in IP column to inetinet 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.:

PG::DatatypeMismatch:
ERROR:  default for column "sign_up_ip" cannot be cast automatically to type inet

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.

Convert varchar column to inet

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
Source Link

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.