将 s3 文件复制到 Redshift table,IDENTITY 列不带 EXPLICIT_IDS
COPY s3 files to Redshift table with IDENTITY column without EXPLICIT_IDS
我有一堆 s3 文件要复制到 Redshift(使用 AWS Data Pipelines 和 RedshiftCopyActivity)。挑战在于我的 s3 文件比目标 Redshift table 少一列。
Table 本身有 "id" 列 - 一个 IDENTITY 列,其值在插入期间自动生成。
我知道我 should/could 正在使用 RedshiftCopyActivity 的 transformSql 属性 但我未能构建有用的查询。执行总是returns我一个错误:
Exception ERROR: cannot set an identity column to a value
更多细节:
标识列是 table.
的第一列
数据已成功插入 table 中,称为 staging,这是应该的。此外,我看到我的 transformSQL 是 运行,数据被插入到 table 中,称为 staging2。日志显示:
create temporary table staging2 as select myField1, myField2, ..., myFieldN from staging
但之后是:
INSERT INTO target_table SELECT * FROM staging2
导致错误发生。
那么,我怎样才能解决这个问题并让 Redshift 忽略我少提供一列的事实呢?
也许解决方案是将 "id" 列作为最后一列,我仍然没有尝试这一列。老实说,我不喜欢这听起来很脆弱的方法。
逗你开心tabletable-姓名
id(身份) |名称(字符串)|地址(字符串)
复制命令应该像
COPY table-name
Name , Address
FROM data-source
CREDENTIALS 'aws-auth-args';
注意:复制语法
COPY table-name
[ column-list ]
FROM data_source
[ WITH ] CREDENTIALS [AS] 'aws-auth-args'
[ [ FORMAT ] [ AS ] data_format ]
[ [ parameter [ argument ] [, ... ] ]
最后,我无法使用 RedshiftCopyActivity 使其正常工作。
它总是抱怨如何不能将值设置为标识列。事件 transformSQL 参数没有帮助。
适合我需要的解决方案是使用运行简单 shell 脚本的 ShellCommandActivity。
基本上,想法是在 运行 提到的 shell 脚本的 EC2 运行 上安装 PSQL,使用 PSQL 连接到 Redshift 并触发将数据从 S3 复制到 Redshift 表的 COPY 命令。
使用 COPY 命令的标识列没有问题。
我有一堆 s3 文件要复制到 Redshift(使用 AWS Data Pipelines 和 RedshiftCopyActivity)。挑战在于我的 s3 文件比目标 Redshift table 少一列。 Table 本身有 "id" 列 - 一个 IDENTITY 列,其值在插入期间自动生成。
我知道我 should/could 正在使用 RedshiftCopyActivity 的 transformSql 属性 但我未能构建有用的查询。执行总是returns我一个错误:
Exception ERROR: cannot set an identity column to a value
更多细节: 标识列是 table.
的第一列数据已成功插入 table 中,称为 staging,这是应该的。此外,我看到我的 transformSQL 是 运行,数据被插入到 table 中,称为 staging2。日志显示:
create temporary table staging2 as select myField1, myField2, ..., myFieldN from staging
但之后是:
INSERT INTO target_table SELECT * FROM staging2
导致错误发生。
那么,我怎样才能解决这个问题并让 Redshift 忽略我少提供一列的事实呢? 也许解决方案是将 "id" 列作为最后一列,我仍然没有尝试这一列。老实说,我不喜欢这听起来很脆弱的方法。
逗你开心tabletable-姓名
id(身份) |名称(字符串)|地址(字符串)
复制命令应该像
COPY table-name
Name , Address
FROM data-source
CREDENTIALS 'aws-auth-args';
注意:复制语法
COPY table-name
[ column-list ]
FROM data_source
[ WITH ] CREDENTIALS [AS] 'aws-auth-args'
[ [ FORMAT ] [ AS ] data_format ]
[ [ parameter [ argument ] [, ... ] ]
最后,我无法使用 RedshiftCopyActivity 使其正常工作。 它总是抱怨如何不能将值设置为标识列。事件 transformSQL 参数没有帮助。
适合我需要的解决方案是使用运行简单 shell 脚本的 ShellCommandActivity。 基本上,想法是在 运行 提到的 shell 脚本的 EC2 运行 上安装 PSQL,使用 PSQL 连接到 Redshift 并触发将数据从 S3 复制到 Redshift 表的 COPY 命令。
使用 COPY 命令的标识列没有问题。