Data cursor

To execute the SQL commands (spatial or otherwise), we will create a data cursor. The cursor is part of the connection class and will be used to execute statements using the execute command. It is also used to access query results, which are converted into a list and iterated using a for loop:

from pymapd import connect
connection = connect(user="mapd", password= "{password}",
host="{my.host.com}", dbname="mapd")
cursor = connection.cursor()
sql_statement = """SELECT name FROM county;"""
cursor.execute(sql_statement)
results = list(cursor)
for result in results:
print(result[0])

The result is a list of tuples, which contain (in this case) only the name of the county, accessed using a zero index to get it out of the tuple.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset