How can I return all data back from query in Python

153 Views Asked by At

How can I return all the data back from the correct amount of rows in this query. I have it as for row in results['results']: print(row) but I'm sure thats wrong because when I run it in sql it returns more. Thanks in advance!

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)
1

There are 1 best solutions below

0
On

Query was structured with too many spaces in between select statement. Rewrote the query and it worked as expected.

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')")