由于短划线字符而无法查询Athena表

时间:2018-07-31 00:42:53

标签: amazon-web-services amazon-athena

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

SELECT * FROM 
fpa-dev
LIMIT 10

它给了我这个错误:

  

外部输入'-'期望{,'。',',','add','as','all','some','any','where','group','order' ,“具有”,“限制”,“在”,“否”,“子字符串”,“位置”,“ tinyint”,“ smallint”,“ integer”,“ date”,“ time”,“ timestamp”,“间隔”,“年”,“月”,“天”,“小时”,“分钟”,“第二”,“区域”,“连接”,“交叉”,“内部”,“左”,“右” ,“完整”,“自然”,“过滤器”,“超过”,“分区”,“范围”,“行”,“在先”,“跟随”,“当前”,“行”,“模式”,“评论”,“查看”,“替换”,“授予”,“撤消”,“特权”,“公开”,“选项”,“解释”,“分析”,“格式”,“类型”,“文本” ,“ graphviz”,“逻辑”,“分布式”,“ validate”,“ show”,“ tables”,“ views”,“ schemas”,“ catalogs”,“ columns”,“ column”,“ use”,“分区'',``函数'',``联合'',``除外'',``相交'',``到'',``系统'',``bernoulli'',``泊松'',``表样本'',``数组'',``地图'',``集合'' ,“重置”,“会话”,“数据”,“开始”,“事务”,“提交”,“回滚”,“工作”,“隔离”,“级别”,“可序列化”,“可重复”,“ C省略,未提交,读,写,仅,调用,输入,输出,级联,限制,包括,排除,属性,“ nfd”,“ nfc”,“ nfkd”,“ nfkc”,“ if”,“ nullif”,“ coalesce”,标识符,digit_identifier,quoted_identifier,backquoted_identifier}(服务:amazonathena;状态码:400;错误代码:invalidrequestexception;请求ID:1b9aaf21-a83f-4678-b2da-19994e11cfd7)

是否可以查询表中带有“-”的表,还是必须重命名表?

1 个答案:

答案 0 :(得分:8)

您应该使用反引号对表名进行转义,就像保留字一样:

Sub Import()

        Dim strPathFile As String, strFile As String, strPath As String
        Dim strTable As String
        Dim blnHasFieldNames As Boolean

        ' Change this next line to True if the first row in EXCEL worksheet
        ' has field names
        blnHasFieldNames = True

        ' Replace C:\Documents\ with the real path to the folder that
        ' contains the EXCEL files
        strPath = "C:\your_path_here\"

        ' Replace tablename with the real name of the table into which
        ' the data are to be imported
        strTable = "Table1"

        strFile = Dir(strPath & "*.csv")
        Do While Len(strFile) > 0
              strPathFile = strPath & strFile
              DoCmd.TransferText acImportDelim, "", strTable, strPathFile, blnHasFieldNames

        ' Uncomment out the next code step if you want to delete the
        ' EXCEL file after it's been imported
        '       Kill strPathFile

              strFile = Dir()
        Loop

End Sub