Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't Query Athena Table Because of Dash Character

I have a table called fpa-dev in Athena (created by Glue). When I run this simple query:

SELECT * FROM 
fpa-dev
LIMIT 10

it gives me this error:

extraneous input '-' expecting {, '.', ',', 'add', 'as', 'all', 'some', 'any', 'where', 'group', 'order', 'having', 'limit', 'at', 'no', 'substring', 'position', 'tinyint', 'smallint', 'integer', 'date', 'time', 'timestamp', 'interval', 'year', 'month', 'day', 'hour', 'minute', 'second', 'zone', 'join', 'cross', 'inner', 'left', 'right', 'full', 'natural', 'filter', 'over', 'partition', 'range', 'rows', 'preceding', 'following', 'current', 'row', 'schema', 'comment', 'view', 'replace', 'grant', 'revoke', 'privileges', 'public', 'option', 'explain', 'analyze', 'format', 'type', 'text', 'graphviz', 'logical', 'distributed', 'validate', 'show', 'tables', 'views', 'schemas', 'catalogs', 'columns', 'column', 'use', 'partitions', 'functions', 'union', 'except', 'intersect', 'to', 'system', 'bernoulli', 'poissonized', 'tablesample', 'array', 'map', 'set', 'reset', 'session', 'data', 'start', 'transaction', 'commit', 'rollback', 'work', 'isolation', 'level', 'serializable', 'repeatable', 'committed', 'uncommitted', 'read', 'write', 'only', 'call', 'input', 'output', 'cascade', 'restrict', 'including', 'excluding', 'properties', 'nfd', 'nfc', 'nfkd', 'nfkc', 'if', 'nullif', 'coalesce', identifier, digit_identifier, quoted_identifier, backquoted_identifier} (service: amazonathena; status code: 400; error code: invalidrequestexception; request id: 1b9aaf21-a83f-4678-b2da-19994e11cfd7)

Is there any way to query a table with a '-' in it or do I have to rename the table?

like image 843
Spencer Sutton Avatar asked Jul 31 '18 00:07

Spencer Sutton


People also ask

Why do I get the access denied error when I run a query in Amazon Athena?

You can get an "Access Denied" error because of the following reasons: The AWS Identity and Access Management (IAM) user doesn't have one or more of the following permissions: Read the source data bucket. Write the results to the query result bucket.

Are Athena queries case sensitive?

Athena accepts mixed case in DDL and DML queries, but lower cases the names when it executes the query. For this reason, avoid using mixed case for table or column names, and do not rely on casing alone in Athena to distinguish such names.

How do you create a table query in Athena?

Open the Athena console at https://console.aws.amazon.com/athena/ . In the query editor, next to Tables and views, choose Create, and then choose S3 bucket data. In the Create Table From S3 bucket data form, enter the information to create your table, and then choose Create table.

How do I resolve the syntax error column Cannot be resolved in Athena?

SYNTAX_ERROR: Column cannot be resolved The solution is to remove the question mark in Athena or in AWS Glue.


1 Answers

You should escape the table name by using backtick, like with any reserved words:

SELECT * FROM 
`fpa-dev`
LIMIT 10
like image 104
Caldazar Avatar answered Oct 03 '22 02:10

Caldazar