2

I have the following csv file saved in an AWS S3 bucket:

Currency Pair,Spot,Date
AUDJPY,70.123,2019/12/12
SGDUSD,0.72,2019/12/12
CADUSD,0.75,2019/12/12

When I use the AWS s3 web interface and choose the "select from" header, the following syntax runs successfully:

select * from s3object s limit 2

But when I try to reference Currency Pair as below, I get the error Invalid Ion literal at line 1. I also get errors trying [Currency Pair], Currency\ Pair, and 'Currency Pair'

select * from s3object s where `Currency Pair` = 'AUDJPY'

How can I select from a table with a column name with a space? From searching, it seems like special characters apart from underscore are not allowed. Can I either reference columns by index or re-define the schema? I would like to run this in python using boto3.

3
  • Ideally, athena should not have allowed a space in the column name docs.aws.amazon.com/athena/latest/ug/… Commented Feb 13, 2020 at 22:41
  • Try using the alias with double quotes. Select * from s3object s where s."Currency Pair" = 'AUDJPY'. See if this reference helps: docs.aws.amazon.com/AmazonS3/latest/dev/… Commented Feb 13, 2020 at 22:56
  • 1
    Aha @SS_DBA - that works! Commented Feb 13, 2020 at 23:04

1 Answer 1

3

Try using the alias with double quotes.

Select * from s3object s where s."Currency Pair" = 'AUDJPY'.

Reference: https://docs.aws.amazon.com/AmazonS3/latest/dev/s3-glacier-select-sql-reference-select.html

Sign up to request clarification or add additional context in comments.

1 Comment

I found also that one can use that sort of syntax to return a specific field in the input that has a space: Expression="SELECT s.\"Currency Pair\" FROM s3object s WHERE s."Currency Pair" = 'AUDJPY'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.