雪花 |插入覆盖失败,表达式类型与列数据类型不匹配,期望 TIMESTAMP_NTZ(9) 但列得到 FLOAT

Snowflake | Insert overwrite fails with Expression type does not match column data type, expecting TIMESTAMP_NTZ(9) but got FLOAT for column

尝试将具有 x+y 列的 table 中的覆盖数据插入具有 x+z 列的 table 并出现错误 SQL compilation error: Expression type does not match column data type, expecting TIMESTAMP_NTZ(9) but got FLOAT for column DATEMODIFIED。 在这种情况下,两个 table 上 DATEMODIFIED 的数据类型都是 TIMESTAMP_NTZ(9)。 查询如下

insert overwrite into tgt_table
select x1,x2,x3, DATEMODIFIED,  null as z1, null as z2 from 
(select x1,x2,x3, DATEMODIFIED from src_table)

注:

insert overwrite into tgt_table
select x1,x2,x3, DATEMODIFIED::TIMESTAMP_NTZ  as DateModified,  null as z1, null as z2 from 
(select x1,x2,x3, DATEMODIFIED::TIMESTAMP_NTZ  as DateModified from src_table)

我怀疑目标 table 中列的顺序不同。 尝试在您的命令中定义目标列,如下所示:

insert overwrite into tgt_table (x1,x2,x3, DATEMODIFIED, z1, z2)
select x1,x2,x3, DATEMODIFIED,  null as z1, null as z2 from 
(select x1,x2,x3, DATEMODIFIED from src_table)

参考:INSERT target_col_name