This is the only / best way to do this for just run the query, do I have python store it in an array, manipulate the array in python, and then run another sql to output to the database?
Not the only way (see other answers), but IMHO is the best and, of course, the easiest. This requires only the PostgreSQL library (I use psycopg ). The standard interface is described in PEP 249 .
SELECT example with psycopg:
cursor.execute("SELECT * FROM students WHERE name=%(name)s;", globals())
and INSERT :
cursor.execute("INSERT INTO Foobar (t, i) VALUES (%s, %s)", ["I like Python", 42])
source share