Search code examples
postgresqltypescastingcreate-table

Postgres CREATE TABLE AS SELECT with unknown column type


I want to create a table with the following query:

create table something as
select 
      other_id, 
      other_title, 
      '0.0.0.0' as IP, 
      1 as used 
from
      other_table

But Postgres complains that:

column "ip" has type "unknown"

How can I specify it to be of type char?


Solution

  • You need to explicitly cast your column, like this:

    '0.0.0.0'::INET as IP,