我正在尝试通过 Python 脚本列出 Amazon AWS Athena 中数据库中的所有表。这是我的脚本:
data = {'name':['database1', 'database-name', 'database2']}
# Create DataFrame
df = pd.DataFrame(data)
for index, schema in df.iterrows():
tables_in_schema = pd.read_sql("SHOW TABLES IN "+schema[0],conn)
运行此程序时出错
当我在 Athena 查询编辑器中运行相同的查询时,出现错误
SHOW TABLES IN database-name
这是错误
DatabaseError: Execution failed on sql: SHOW TABLES IN database-name
An error occurred (InvalidRequestException) when calling the StartQueryExecution operation: line
1:19: mismatched input '-'. Expecting: '.', 'LIKE', <EOF>
unable to rollback
我认为问题在于数据库名称中的连字符“-”。如何在查询中转义?