我正在尝试使用以下方法将数据从一个表插入另一个表:
INSERT INTO production.spend_fact (date, client_id, show_name, network_name,
media_type, spend, load_id, note)
SELECT date, client_id, show_name, network_name, media_type, spend, load_id,
note
FROM staging.spend_fact
JOIN
(SELECT MAX(load_id)
FROM production.load_dim) AS load_id
ON 1=1;
此查询之前有效,直到我向两个表添加了一个新列(注释),现在我收到此错误:
ERROR: column "load_id" is of type integer but expression is of type record
我尝试通过CAST(load_id AS INT)和load_id :: int强制转换“load_id”,但两者都不起作用。
load_id FROM production.load_dim是type serial
load_id FROM production.performance_fact是类型integer
答案 0 :(得分:1)
您需要列名:
cout << "\nTails Percentage: " << fixed << setprecision(1) << tailsPercent << " ";
答案 1 :(得分:0)
您收到此错误,因为load_id是已加入子查询的表别名
当您在选择列表中指定表名时,postgres将选择该表的所有列作为单行类型值
您可以使用以下语法直接访问行值字段:(load_id).max
或者您可以在联接中使用不同的命名:
join (select max(load_id) as load_id FROM production.load_dim) as dummy_name on true
或者您可以使用子查询而不是join:
select date, client_id, show_name, network_name, media_type, spend,
(SELECT MAX(load_id) FROM production.load_dim) ,
note
FROM staging.spend_fact;