title: Postgres: Alter bigint column to inet
body: <p>I am using Postgres 11.1 and have a table that contains a column called ip for holding ipv4 and ipv6 values. (The ips do not contain any colons or dots).</p>
  <p>I now want to alter this column to inet, since I realized the bigint is too small to hold ipv6 values.</p>
  <p>I have tried the following, conversions:</p>
  <pre><code>ALTER TABLE my_table ALTER COLUMN ip TYPE inet USING ip::inet;
  </code></pre>
  <p>but I get <strong>ERROR: cannot cast type bigint to inet</strong></p>
  <p>and</p>
  <pre><code>ALTER TABLE my_table ALTER COLUMN ip TYPE inet USING '0.0.0.0'::inet + cast(ip as bigint);
  </code></pre>
  <p>but I get <strong>ERROR: operator does not exist: inet = character varying</strong></p>
  <p>I have also tried converting the column from bigint to a varchar via:</p>
  <pre><code>alter table my_table alter column ip type varchar using ip::varchar;
  </code></pre>
  <p>only to get <strong>ERROR: operator does not exist: bigint = character varying</strong></p>