【问题标题】:Python SQL/JSON mismatched input 'ON' expecting 'EOF'Python SQL/JSON 不匹配输入 'ON' 期望 'EOF'
【发布时间】:2017-02-09 16:29:34
【问题描述】:

我正在使用可以通过 JSON 发送 sql 查询的 SDK,但是我收到了错误:

  File "/usr/lib/python2.7/site-packages/requests/models.py", line 893, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: mismatched input 'ON' expecting 'EOF' for url: https://solarwinds-orion:17778/SolarWinds/InformationService/v3/Json/Query

这是我正在使用的代码:

swis = SwisClient(hostname, username, password, verify=v_path)   
query = """
SELECT NodeID,NodeName,IPAddress,IP,IP_Address,NodeIPAddresses 
FROM Orion.Nodes ON
    inner join Orion.NodesCustomProperties CP
    on ON.NodeID = CP.NodeID
WHERE CP.smartnet = 1
"""
results = swis.query(query)

这是架构的链接

自定义属性 - http://solarwinds.github.io/OrionSDK/schema/Orion.NodesCustomProperties.html 节点 - http://solarwinds.github.io/OrionSDK/schema/Orion.Nodes.html

根据我在内部联接上搜索的内容,该查询应该没问题?

【问题讨论】:

  • ON 是保留关键字。使用不同的表别名。还可以在选择列之前使用表别名以避免列名不明确错误。

标签: python sql json


【解决方案1】:

将您的表别名从 ON 更改为其他名称,您应该没问题:

SELECT NodeID      -- You should also be using the appropriate table alias
      ,NodeName    -- for each of these columns.
      ,IPAddress
      ,IP
      ,IP_Address
      ,NodeIPAddresses 
FROM Orion.Nodes N
    inner join Orion.NodesCustomProperties CP
        on N.NodeID = CP.NodeID
WHERE CP.smartnet = 1

这是一个错误,因为on 是保留关键字,如@9​​87654324@ 或and,对sql 编译器很重要。

【讨论】:

  • 啊,很有道理!
猜你喜欢
  • 2022-01-05
  • 2019-11-02
  • 2022-06-21
  • 1970-01-01
  • 2013-10-04
  • 1970-01-01
  • 2020-04-28
  • 2021-12-10
  • 1970-01-01
相关资源
最近更新 更多