amazon-web-services - “无法复制到不存在的表”错误,但表存在于 Amazon Redshift 中
问题描述
我在 Redshift 中设置了一个表,现在想用来自不同区域的 s3 存储桶的数据填充它。我正在使用 COPY 命令,但出现错误:
"psycopg2.errors.InternalError_: Cannot COPY into nonexistent table customcontent_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:// 前缀和存储桶名称。我不认为这是导致此错误的原因,但您需要修复它。
我最初的想法是为什么您会收到此错误消息,因为此会话未找到该表。Redshift 会话有一个“搜索路径”的概念,它告诉当前会话在哪里查找表(哪些模式)。如果是这种情况,那么最简单的解决方案(或者至少是最容易解释的)就是将表的模式添加到 COPY 命令中:
copy schema_name.customcontent_table from ...
这将告诉 Redshift 在哪里可以找到该表。如果您想设置搜索路径,可以在此处阅读 - https://docs.aws.amazon.com/redshift/latest/dg/r_search_path.html
如果这不是问题,那么我们需要更深入地挖掘。
推荐阅读
- c++ - 作为参数传递给函数模板时如何隐式转换类模板对象?
- dynamics-crm - 将社交窗格中的活动配置为默认“进行中”
- c# - 如果布尔值标记为 false,Selenium C# 显示自定义异常?
- javascript - 修改 href 选择器以排除锚标记
- javascript - Firebase 使用 Javascript 查询数组或对象
- sql-server - 如何在两列中聚合两列,然后再聚合一些?
- python - 根据熊猫数据框中用空格分隔的类别复制记录
- c - 从 PCM 数据创建 .wav 文件
- javascript - 灵活的算法来计算所有可能场景的可能性
- android - 无法从片段中的 Firebase 填充列表视图