8

data sample

I used AWS Glue Console to create a table from S3 bucket in Athena. You can see a relevant part on the screenshot above. I obfuscated column name, so assume the column name is "a test column". I would like to select the records with value D in that column. The query I tried to run is:

SELECT 
    * 
FROM 
    table 
WHERE 
    "a test column" = "D"

Nothing is returned. I also tried to use IS instead of =, as well as to surround D with single quotes instead of double quotes within the WHERE clause:

-- Tried this
WHERE 
    "a test column" = 'D'

-- Tried this
WHERE 
    "a test column" IS "D"

-- Tried this
WHERE 
    "a test column" IS 'D'

Nothing works. Can someone help? Thank you.

The error message I got is

Mismatched input 'where' expecting (service: amazon athena; status code: 400; error code: invalid request exception; request id: 8f2f7c17-8832-4e34-8fb2-a78855e3c17d)

8
  • Believe that table and column names must be lower case and may not contain any special characters other than underscore. Can you control the column name?
    – jarmod
    Commented Feb 3, 2020 at 15:57
  • 1
    Remove the quotes from around "a test column" - these are not needed in Athena Commented Feb 3, 2020 at 15:58
  • Can you give me what is the output of show create table <table-name> ? Commented Feb 3, 2020 at 15:59
  • The column name is automatically created by the Glue crawler, so there is space in the middle. That is why " " is needed around "a test column".
    – L.Yang
    Commented Feb 3, 2020 at 16:04
  • show create table <table-name> returns an error below -- Queries of this type are not supported (Service: AmazonAthena; Status Code: 400; Error Code: InvalidRequestException; Request ID: b08366a0-2eaf-4434-8ccf-eee473fa343b)
    – L.Yang
    Commented Feb 3, 2020 at 16:06

2 Answers 2

18

Problem with the query syntax. Use single quotes (') when you refer to a string values, because double quotes refer to a column name in your table.

SELECT 
    * 
FROM 
    table 
WHERE 
    "column_name" = 'D'
0

The unexpected answer (also apologize if I did not say it clearly in the original post) is that, I cannot add "limit 200" in front of the where clause. I have to add it in the end. Hope it helps others.

1
  • 1
    you didn't posted the full SQL query in your question? Commented Feb 6, 2020 at 4:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.