Postgres CREATE TABLE AS SELECT具有未知列类型

Fer*_*eak 3 postgresql types casting create-table

我想用以下查询创建一个表:

create table something as
select 
      other_id, 
      other_title, 
      '0.0.0.0' as IP, 
      1 as used 
from
      other_table
Run Code Online (Sandbox Code Playgroud)

但Postgres抱怨说:

column "ip" has type "unknown"
Run Code Online (Sandbox Code Playgroud)

如何将其指定为类型char

mvp*_*mvp 5

您需要显式转换列,如下所示:

'0.0.0.0'::INET as IP,
Run Code Online (Sandbox Code Playgroud)