April 2018
Beginner to intermediate
440 pages
11h 36m
English
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 connectconnection = 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.