'Cannot COPY into nonexistent table' 错误,但 Amazon Redshift 中存在 table
'Cannot COPY into nonexistent table' error but table exists in Amazon Redshift
我在 Redshift 中设置了一个 table,现在想用来自不同区域的 s3 存储桶的数据填充它。我正在使用 COPY 命令,但出现错误:
"psycopg2.errors.InternalError_: Cannot COPY into nonexistent table customcontent_table"
我不知道如何修复它,因为 table 显然已经存在。我的语法有错误吗?我的代码:
sql = "copy customcontent_table from 'test/2021/03/29/20/20/CustomContent.snappy.parquet' credentials 'aws_access_key_id=AA;aws_secret_access_key=zz' format parquet region 'us-west-2';"
cur = con.cursor()
cur.execute("begin;")
cur.execute(sql)
cur.execute("commit;")
con.close()
所以您对 S3 对象的引用看起来不正确。应该类似于(根据 AWS 文档):
copy listing
from 's3://mybucket/data/listings_pipe.txt'
access_key_id '<access-key-id>'
secret_access_key '<secret-access-key'
...;
您似乎只有对象键,但没有 s3:// 前缀和存储桶名称。我认为这不是导致此错误的原因,但您需要修复它。
关于您收到此错误消息的原因,我最初的想法是因为此会话未找到 table。 Redshift 会话有一个“搜索路径”的概念,它告诉当前会话在哪里寻找 tables(哪些模式)。如果是这种情况,那么最简单的解决方案(或者至少是最容易解释的)就是将 table 的架构添加到 COPY 命令:
copy schema_name.customcontent_table from ...
这将告诉 Redshift 在哪里可以找到 table。如果你想设置搜索路径,你可以在这里阅读 - https://docs.aws.amazon.com/redshift/latest/dg/r_search_path.html
如果这不是问题所在,那么我们需要深入挖掘。
我在 Redshift 中设置了一个 table,现在想用来自不同区域的 s3 存储桶的数据填充它。我正在使用 COPY 命令,但出现错误:
"psycopg2.errors.InternalError_: Cannot COPY into nonexistent table customcontent_table"
我不知道如何修复它,因为 table 显然已经存在。我的语法有错误吗?我的代码:
sql = "copy customcontent_table from 'test/2021/03/29/20/20/CustomContent.snappy.parquet' credentials 'aws_access_key_id=AA;aws_secret_access_key=zz' format parquet region 'us-west-2';"
cur = con.cursor()
cur.execute("begin;")
cur.execute(sql)
cur.execute("commit;")
con.close()
所以您对 S3 对象的引用看起来不正确。应该类似于(根据 AWS 文档):
copy listing
from 's3://mybucket/data/listings_pipe.txt'
access_key_id '<access-key-id>'
secret_access_key '<secret-access-key'
...;
您似乎只有对象键,但没有 s3:// 前缀和存储桶名称。我认为这不是导致此错误的原因,但您需要修复它。
关于您收到此错误消息的原因,我最初的想法是因为此会话未找到 table。 Redshift 会话有一个“搜索路径”的概念,它告诉当前会话在哪里寻找 tables(哪些模式)。如果是这种情况,那么最简单的解决方案(或者至少是最容易解释的)就是将 table 的架构添加到 COPY 命令:
copy schema_name.customcontent_table from ...
这将告诉 Redshift 在哪里可以找到 table。如果你想设置搜索路径,你可以在这里阅读 - https://docs.aws.amazon.com/redshift/latest/dg/r_search_path.html
如果这不是问题所在,那么我们需要深入挖掘。