Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st. We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here. Need help or have questions? Drop us a line at [email protected]
curs = conn.cursor()
query = """
CREATE TABLE IF NOT EXISTS """+TABLENAME+""" (
state CHAR(2) NOT NULL,
city VARCHAR NOT NULL,
population BIGINT
CONSTRAINT my_pk PRIMARY KEY (state, city))
"""
curs.execute(query)
Bulk insert a set of data, using nested arrays for each record, and executing multiple upserts.
Finally, run a query to return an aggregated group-by and return as a Dictionary object.
curs = conn.cursor(cursor_factory=phoenixdb.cursor.DictCursor)
query = """SELECT state as "State",count(city) as "City Count",sum(population) as "Population Sum"
FROM us_population
GROUP BY state
ORDER BY sum(population) DESC"""
curs.execute(query)
print(curs.fetchall())
When the above is run in a session, it will return the following results.