HiveQL - 如何在 WHERE 子句中使用转义关键字?
HiveQL - How to use escaped keywords in a WHERE clause?
我正在尝试通过仅选择满足特定条件的案例来查询 table。它是在 R 脚本中从 Beeline 调用的查询。
问题是必须满足这个条件的字段有一个保留字作为列名:'table'.
每当我在 AWS-EMR 集群中 运行 时:
SELECT ... FROM ... WHERE `table` = 'something' AND year = 2018
我收到以下错误:
bash: table: command not found
Connecting to jdbc:hive2://localhost:10000
Connected to: Apache Hive (version 2.3.2-amzn-0)
Driver: Hive JDBC (version 2.3.2-amzn-0)
Transaction isolation: TRANSACTION_REPEATABLE_READ
. . . . . . . . . . . . . . . . Error: Error while compiling statement: FAILED: ParseException line 1:242 cannot recognize input near '=' ''something'' 'and' in expression specification (state=42000,code=40000)
Closing: 0: jdbc:hive2://localhost:10000
ExitValue: 1
以粗体标记的两个块都应修复。请注意关键字 'table' 已经用反引号转义了。
我已经在网上搜索过,但仍然没有找到合适的解决方案。任何帮助将不胜感激。
正如@SamsonScharfrichter 在评论中指出的那样:
Short-term workaround: try escaping back-ticks i.e. \`table\` or maybe \`table\`
这解决了我的问题。
我正在尝试通过仅选择满足特定条件的案例来查询 table。它是在 R 脚本中从 Beeline 调用的查询。 问题是必须满足这个条件的字段有一个保留字作为列名:'table'.
每当我在 AWS-EMR 集群中 运行 时:
SELECT ... FROM ... WHERE `table` = 'something' AND year = 2018
我收到以下错误:
bash: table: command not found
Connecting to jdbc:hive2://localhost:10000
Connected to: Apache Hive (version 2.3.2-amzn-0)
Driver: Hive JDBC (version 2.3.2-amzn-0)
Transaction isolation: TRANSACTION_REPEATABLE_READ
. . . . . . . . . . . . . . . . Error: Error while compiling statement: FAILED: ParseException line 1:242 cannot recognize input near '=' ''something'' 'and' in expression specification (state=42000,code=40000)
Closing: 0: jdbc:hive2://localhost:10000
ExitValue: 1
以粗体标记的两个块都应修复。请注意关键字 'table' 已经用反引号转义了。
我已经在网上搜索过,但仍然没有找到合适的解决方案。任何帮助将不胜感激。
正如@SamsonScharfrichter 在评论中指出的那样:
Short-term workaround: try escaping back-ticks i.e. \`table\` or maybe \`table\`
这解决了我的问题。