简体   繁体   中英

Unable to import s3 data to RDS(Postgresql) using aws_commons extension

I am trying to import s3 file(CSV file) to Postgre sql rds instance. I am running s3 import queries from rds instance as per AWS docs but i am getting below error

ERROR: syntax error at or near ":" LINE 5: :'s3_uri', ^ SQL state: 42601 Character: 76

Query i used for downloading s3 file is below:

SELECT aws_s3.table_import_from_s3( 't1', '', '(format csv)', :'s3_uri', );

Running query as per AWS doc: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.Procedural.Importing.html#USER_PostgreSQL.S3Import.Overview

SELECT aws_s3.table_import_from_s3( 't1', '', '(format csv)', :'s3_uri', );

:' is not a valid syntax. :'s3_uri' , including the leading colon, need to be replaced with a s3 URI. When you are done, there should be no literal colon there outside the quotes.

I had the same error. Solved it with these steps:

  1. upgrade postgres to version 14.4 (though 12.4 also works )
  2. install aws_commons CREATE EXTENSION aws_s3 CASCADE;
  3. run
SELECT aws_commons.create_aws_credentials('access_key','secret_key') as credentials;

SELECT aws_commons.create_s3_uri('bucket_name', 'file_name.csv') AS s3_uri_1 \gset

SELECT aws_s3.table_import_from_s3('table_name','','(format csv)',:'s3_uri_1');

References:

  1. Importing data from Amazon S3 into an RDS for PostgreSQL DB instance
  2. Examples of importing data from Amazon S3 into an RDS for PostgreSQL DB instance

Try add \n before:

SELECT aws_s3.table_import_from_s3( 't1', '', '(format csv)', 
:'s3_uri', );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM