【问题标题】:It occur error when try to import csv to PostgreSQL RDS from S3 bucket with using AWS_S3 extension尝试使用 AWS_S3 扩展从 S3 存储桶将 csv 导入 PostgreSQL RDS 时发生错误
【发布时间】:2021-01-11 19:05:35
【问题描述】:

我尝试使用 aws_s3 扩展名将 csv 文件从 s3 存储桶导入 postgres aurora rds。当我在 psql 控制台上执行此操作时,它首先发生错误,然后它是成功的。为什么首先出现错误?

$ psql -h 127.0.0.1 -p 5432 -U user mydb
Password for user mydb:
psql (12.2, server 11.7)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.

mydb=> select *
from aws_s3.table_import_from_s3(
    'my_table',
    '',
    '(format csv, header false)',
    aws_commons.create_s3_uri(
        'my_bucket',
        format('imports/%s/my_file.csv', 'sub_dir'),
        'ap-northeast-1'
    )
);
ERROR:  Unable to complete COPY from S3, HTTP error code: 168
CONTEXT:  SQL function "table_import_from_s3" statement 1
mydb=>
mydb=>
mydb=> select *
from aws_s3.table_import_from_s3(
    'my_table',
    '',
    '(format csv, header false)',
    aws_commons.create_s3_uri(
        'my_bucket',
        format('imports/%s/my_csv.csv', 'sub_dir'),
        'ap-northeast-1'
    )
);
                                                  table_import_from_s3
------------------------------------------------------------------------------------------------------------------------
 18638 rows imported into relation "my_table" from file imports/sub_dir/my_file.csv of 2033585 bytes
(1 row)

重复发生这种奇怪的现象。

【问题讨论】:

    标签: amazon-web-services amazon-s3 amazon-aurora


    【解决方案1】:

    我解决了这个错误。原因是我要在没有指定转义双引号选项的情况下导入文件。我试图导入如下文件。

    aaa,bbb,ccc
    aaa,bbb,ccc
    "aaa",bbb,ccc
    

    双引号转义需要指定选项。

    select *
    from aws_s3.table_import_from_s3(
        'my_table',
        '',
        '(format csv, escape ''"'')',
        aws_commons.create_s3_uri(
            'my_bucket',
            format('imports/%s/my_file.csv', 'sub_dir'),
            'ap-northeast-1'
        )
    );
    
    

    【讨论】:

      猜你喜欢
      • 2022-10-14
      • 1970-01-01
      • 2020-02-11
      • 2022-08-16
      • 1970-01-01
      • 1970-01-01
      • 2021-05-19
      • 1970-01-01
      • 2020-05-11
      相关资源
      最近更新 更多