在 Redshift 维度 table 中创建默认值行以防止报告中出现空值

Creating default value row in Redshift dimension table to prevent null values in reports

我正在将用于初始开发的数据仓库架构和默认数据加载从 MySQL 移植到 Redshift 以进行生产。初始默认数据创建为维度表中的一行,并根据 http://www.kimballgroup.com/2010/10/design-tip-128-selecting-default-values-for-nulls/.

在自动增量列中设置了 -1 值

将架构移至 Redshift 后,应将列从 auto_increment 更改为标识,以保留数据库主键生成,但这不再允许插入标识列返回

ERROR: cannot set an identity column to a value
SQL state: 0A000

ETL 加载作业是否应该负责在这种情况下自动递增维度键,或者是否有另一个创建插入值?

据我所知,覆盖自动生成的值对 INSERT 不起作用。如果您有可能将数据上传到 S3,您可以使用 Redshift 的 COPY 命令将数据从 S3 加载到 table。它让您指定选项 EXPLICIT_IDS,例如:

COPY your_table from 's3://path_to_your/data.csv' CREDENTIALS '' EXPLICIT_IDS;

来自documentation

Use EXPLICIT_IDS with tables that have IDENTITY columns if you want to override the autogenerated values with explicit values from the source data files for the tables. If the command includes a column list, that list must include the IDENTITY columns to use this parameter. The data format for EXPLICIT_IDS values must match the IDENTITY format specified by the CREATE TABLE definition.