Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python中从查询返回所有数据_Python_Sql_Solarwinds Orion_Swissql - Fatal编程技术网

如何在Python中从查询返回所有数据

如何在Python中从查询返回所有数据,python,sql,solarwinds-orion,swissql,Python,Sql,Solarwinds Orion,Swissql,如何在此查询中从正确数量的行返回所有数据。对于results['results']:print(row)中的row,我将其设置为,但我确信这是错误的,因为当我在sql中运行它时,它会返回更多。提前谢谢 results = swis.query("SELECT " "n.Caption AS NodeCaption" ",n.IP_Address AS IPAddress" ",n.NodeID"

如何在此查询中从正确数量的行返回所有数据。对于results['results']:print(row)中的row,我将其设置为
,但我确信这是错误的,因为当我在sql中运行它时,它会返回更多。提前谢谢

results = swis.query("SELECT "
                 "n.Caption AS NodeCaption"
                 ",n.IP_Address AS IPAddress"
                 ",n.NodeID"
                 ",a.ApplicationID "
                 ",n.Uri AS NodeUri "
                 ",n.Uri AS AppUri "
                 "FROM Orion.Nodes n "
                 "JOIN Orion.APM.Application a ON n.NodeID = a.NodeID "
                 "JOIN Orion.APM.ApplicationTemplate at ON a.ApplicationTemplateID = at.ApplicationTemplateID "
                 "WHERE at.Name IN('Process_Monitor - Dynatrace Linux OneAgent', 'Service_Monitor - Dynatrace"
                 "OneAgent Service')")

for row in results['results']:
print(row)

查询的结构在select语句之间有太多空格。重写查询后,它就按预期工作了

query = ("SELECT\n"
         "n.Caption AS NodeCaption\n"
         ",n.IP_Address AS IPAddress\n"
         ",n.NodeID\n"
         ",a.ApplicationID\n"
         ",n.Uri AS NodeUri\n"
         ",a.Uri AS AppUri\n"
         "FROM Orion.Nodes n\n"
         "JOIN Orion.APM.Application a ON n.NodeID = a.NodeID\n"
         "JOIN Orion.APM.ApplicationTemplate at ON a.ApplicationTemplateID = at.ApplicationTemplateID\n"
         "WHERE at.Name IN ('Process_Monitor - Dynatrace Linux OneAgent', 'Service_Monitor - Dynatrace OneAgent "
         "Service')")