由于破折号,无法查询 Athena Table

Can't Query Athena Table Because of Dash Character

我在 Athena 中有一个名为 fpa-dev 的 table(由 Glue 创建)。当我 运行 这个简单的查询时:

SELECT * FROM 
fpa-dev
LIMIT 10

它给我这个错误:

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)

有什么方法可以查询其中带有“-”的 table 还是我必须重命名 table?

您应该像使用任何保留字一样使用反引号转义 table 名称:

SELECT * FROM 
`fpa-dev`
LIMIT 10

我 运行 遇到了一个类似的列名问题,其中使用反引号转义不起作用(就像我在 spark 中所做的那样)。请改用引号。

SELECT * FROM 
"fpa-dev"
LIMIT 10

如果您有需要转义的列(如名称中的 .),您还可以使用引号:

SELECT "project.userId" from sometable

我看到 Spencer Sutton 在评论中提出了同样的建议,但它需要一个答案。