【发布时间】:2019-09-09 10:19:09
【问题描述】:
在 Amazon Redshift 中,我尝试从临时表中的表中批量插入值。 但是我只想插入表中不存在值组合(主键)的值,以避免添加重复。
表格的 DDL 下方
• clusters_typologies 表(我要插入数据时的表)
create table if not exists clusters.clusters_typologies
(
cluster_id BIGINT,
typology_id BIGINT,
semantic_id BIGINT,
primary key (cluster_id, typology_id, semantic_id)
);
使用下面的查询创建临时表,然后正确插入所有字段。
CREATE TEMPORARY TABLE temporary (
cluster_id bigint,
typology_name varchar(100),
typology_id bigint,
semantic_name varchar(100),
semantic_id bigint
);
现在当我尝试使用该查询插入时
INSERT INTO clusters.clusters_typologies (cluster_id, typology_id,semantic_id)
(SELECT temp.cluster_id, temp.typology_id, temp.semantic_id
FROM temporary temp
WHERE NOT EXISTS(SELECT 1
FROM clusters_typologies
where cluster_id = temp.cluster_id
and typology_id = temp.typology_id
and semantic_id = temp.semantic_id));
我遇到了这个错误,我不知道如何让它工作。
无效操作:由于内部错误,不支持这种类型的关联子查询模式;
任何人都知道如何修复或如何使用复合键在表中插入避免重复的最佳方法。
谢谢。
【问题讨论】:
标签: amazon-redshift