queryText with WHERE condition in aws_s3.query_export_to_s3 not working

Viewed 37

Trying to execute the query on lambda in python using psycopg2.

query = "SELECT * FROM aws_s3.query_export_to_s3('SELECT * from sample WHERE name='text1'','s3-bucket-name','file-path')".

Gives me an error - syntax error at or near "text1".

Meanwhile, this query is running fine with name with type number but not working with the string type, and also this query is working fine without query_export_to_s3. It seems to me like query_export_to_s3 can't work with string in WHERE condition.

Thanks in advance for any suggestion

1 Answers

Escape your single quotes with single quotes.

query = "SELECT * FROM aws_s3.query_export_to_s3('SELECT * from sample WHERE name=''text1''','s3-bucket-name','file-path')"
Related