- Newest
- Most votes
- Most comments
When working with nested JSON data in Redshift Spectrum that contains reserved words like "timestamp" as attribute names, you have a few options to handle this situation:
- Use case-sensitive identifiers: You can enable case-sensitive identifiers in your Redshift session by setting:
SET enable_case_sensitive_identifier to TRUE;
Then query using double quotes around the attribute name:
SELECT e.data.user_id::int AS userid, e.data.api AS platform, l."timestamp" FROM "glue-geofencing"."events_raw" e LEFT JOIN e.data.events l ON true;
- Use LOWER_ATTRIBUTE_NAMES function: If your JSON data contains mixed-case attribute names, you can use the LOWER_ATTRIBUTE_NAMES function to convert all attribute names to lowercase, which might help with the reserved word issue:
CREATE TABLE normalized_data AS SELECT LOWER_ATTRIBUTE_NAMES(data) AS data FROM "glue-geofencing"."events_raw";
Then query the normalized data.
- Enable case-sensitive SUPER attributes: As an alternative to LOWER_ATTRIBUTE_NAMES, you can use the
enable_case_sensitive_super_attributeconfiguration option, which allows Redshift to recognize case in SUPER attribute names.
Note that when working with nested data in Redshift Spectrum, there are limitations to be aware of, such as maximum nesting depth of 100 and restrictions on how you can query nested arrays and maps.
If you're still having issues, you might need to adjust your Glue table definition. While removing backticks worked as a workaround, ideally you should be able to define the schema with proper quoting for reserved words.
Sources
LOWER_ATTRIBUTE_NAMES function - Amazon Redshift
Nested data limitations (preview) - Amazon Redshift
SUPER configurations - Amazon Redshift
answered a year ago
After taking another close look, I actually realized that it's possible to create the Glue Table reserved-word attributes without the backticks and it perfectly works on Redshift. So, This is not an issue in reality. Sorry
answered a year ago
✅ Problem:
Glue schema uses backticks for timestamp.
Redshift Spectrum cannot query it directly.
💡 Fix:
When you create the table, avoid backticks — use double quotes + aliasing:
SELECT l."timestamp" AS event_timestamp FROM "glue-geofencing"."events_raw" e CROSS JOIN UNNEST(e.data.events) AS t(l);
If Glue insists on using backticks:
Edit schema in Glue to rename the column to something like timestamp_col (supported via AWS CLI).
Or create a Redshift Spectrum view:
CREATE VIEW events_vw AS SELECT json_extract_path_text(event, 'timestamp') AS event_timestamp FROM "glue-geofencing"."events_raw";
answered a year ago
Relevant content
asked 3 years ago
asked 7 years ago
asked 2 years ago
