【问题标题】:'Cannot COPY into nonexistent table' error but table exists in Amazon Redshift“无法复制到不存在的表”错误,但表存在于 Amazon Redshift 中
【发布时间】:2021-04-07 20:15:01
【问题描述】:

我在 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()    

【问题讨论】:

    标签: amazon-web-services amazon-redshift psycopg2


    【解决方案1】:

    所以您对 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

    如果这不是问题,那么我们需要深入挖掘。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-30
      • 2013-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-21
      • 1970-01-01
      相关资源
      最近更新 更多