postgresql 如何使用带制表符分隔符的“aws_s3.query_export_to_s3”从RDS / Aurora导出到S3?

o75abkj4  于 2023-01-17  发布在  PostgreSQL
关注(0)|答案(1)|浏览(129)

想逃跑

SELECT
     *
 FROM 
 aws_s3.query_export_to_s3(
 'SELECT * FROM <tbl> WHERE <cond>',
 aws_commons.create_s3_uri(
        '<bucket_name>',
        '<file_name>',
        '<region>'
    ),
        options :='format csv, HEADER true, delimiter $$\t$$'
    )
 ;

自定义分隔符规范遵循AWS文档www.example.comhttps://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/postgresql-s3-export.html#postgresql-s3-export-examples-custom-delimiter
但是,由于ERROR: COPY delimiter must be a single one-byte character,无法导出。查询中提供的制表符分隔符符合Postgres COPY命令。
有什么想法吗?

ajsxfq5m

ajsxfq5m1#

您可以使用E ''\t '',它起作用了,请参阅下面的代码

SELECT * from aws_s3.query_export_to_s3('select * from tb', 
   aws_commons.create_s3_uri('s3-bucket', 'data.csv', 'us-east-1'),  
   options :='format csv, HEADER true, delimiter E''\t'' '
);

 rows_uploaded | files_uploaded | bytes_uploaded 
---------------+----------------+----------------
             2 |              1 |             21
(1 row)

相关问题