- Newest
- Most votes
- Most comments
When dealing with column names that contain special characters like dashes in Amazon Athena, you need to use a specific syntax to query them correctly. In your case, with the column name "foo-bar", you should use double quotes to enclose the column name, not backticks. Here's how you can modify your query:
SELECT "foo-bar".name FROM planets_ion_2
This syntax should allow you to access the nested "name" field within the "foo-bar" struct.
It's important to note that while Athena follows SQL standards for the most part, it has some specific rules when it comes to handling special characters in column names. Double quotes are used for column names with special characters, while backticks are typically used in the table creation statements or when working with the Athena console query editor for table names with special characters.
If you continue to experience issues, you might want to consider renaming the column in your data source to avoid the dash, as you've noticed it works fine without it. Alternatively, you could create a view that aliases the column name to something without special characters, which might make querying easier in the long run.
Remember, when creating tables in Athena, it's generally a good practice to avoid using special characters in column names to prevent these kinds of issues and make querying more straightforward.
Sources
Query W3C extended log file format - Amazon Athena
Create databases and tables - Amazon Athena
Relevant content
- asked 6 months ago
- AWS OFFICIALUpdated 3 months ago

The AI's suggestion of putting the column name in double quotes is part of the example I already tried.