Amazon Redshift未在主键列中维护唯一性。

0

【以下的问题经过翻译处理】 嗨,我在Amazon Redshift数据库中创建了一个表, "create table sales(salesid integer not null, listid integer not null, sellerid integer not null, primary key(salesid));"。创建成功后,我向表中插入了值,但该表接受了重复的salesid值,因此该表未遵循任何主键规则。

profile picture
ESPERTO
posta 6 mesi fa17 visualizzazioni
1 Risposta
0

【以下的回答经过翻译处理】 就是这么设计的 - https://docs.aws.amazon.com/redshift/latest/dg/t_Defining_constraints.html 提到:

唯一性约束、主键约束和外键约束只作为信息提供,Amazon Redshift 不会对其进行强制执行。但是,主键和外键会被用作计划提示,如果您的ETL流程或应用程序中的其他流程强制实施其完整性,则应声明它们。

最佳实践是拥有一个清洗数据的ETL流程。一种方法是将数据加载到暂存表中,然后运行 SQL 语句在流程中进行数据去重,最后将其upsert到一个主表集。

希望这能帮到您。

Nick

profile picture
ESPERTO
con risposta 6 mesi fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande