Skip to content

Athena / Glue ALTER TABLE stmt does not work with quoted identifiers

0

Hello,

I would like to report a BUG with regard to unexpected behavior in Amazon Athena. ALTER TABLE where the the table_name (or any part of the fully qualified catalog.schema.table name) fails when quoted with the following error:

ALTER TABLE"catalog"."database"."table" SET TBLPROPERTIES ('key'='value');
-- (InvalidRequestException) ... mismatched input 'TBLPROPERTIES'. Expecting: 'AUTHORIZATION'`

Yet the following SELECT works as expected.

SELECT COUNT(*) FROM "catalog"."database"."table"

asked 2 years ago321 views

2 Answers
1

According to https://docs.aws.amazon.com/athena/latest/ug/reserved-words.html the quoting style is different for DDL statements like ALTER TABLE. Specifically, while SELECT statements use double-quotes ("), DDL statements use backticks (`).

So it would be:

ALTER TABLE `catalog`.`database`.`table` SET TBLPROPERTIES ('key'='value');

and:

SELECT COUNT(*) FROM "catalog"."database"."table"

answered a year ago

0

Thank you for reporting this issue. You're correct that there appears to be unexpected behavior with the ALTER TABLE statement in Amazon Athena when using quoted identifiers.

The behavior you're experiencing where the ALTER TABLE statement fails with quoted identifiers, but SELECT works fine, is indeed inconsistent. This seems to be a limitation or bug in Athena's SQL parser for DDL statements.

As a workaround, you can try using the ALTER TABLE statement without quotes around the identifiers:

ALTER TABLE catalog.database.table SET TBLPROPERTIES ('key'='value');

If you need to use identifiers that contain special characters or spaces, which would normally require quoting, you may need to consider renaming those objects to use simpler names that don't require quotes.

It's worth noting that Athena has some limitations and unsupported DDL operations. While ALTER TABLE SET TBLPROPERTIES is generally supported, the specific syntax with quoted identifiers appears to be problematic.

If this workaround doesn't resolve your issue, or if you absolutely need to use quoted identifiers in your ALTER TABLE statements, I recommend contacting AWS support to report this as a potential bug. They can provide more specific guidance or potentially address this in a future update to Athena.
Sources
Unsupported DDL - Amazon Athena

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.