Dat is wat er gebeurt als je de hele resultatenset dumpt. Met de t
tafel:
create table t (a int, b text);
insert into t (a, b) values (1,'x'), (2,'y');
Psycopg2 gebruiken:
query = "select row_to_json(t) from t"
cursor.execute(query)
rs = cursor.fetchall()
# dump the whole result set
print json.dumps(rs)
print
# dump each column:
for r in rs:
print json.dumps(r[0])
con.close()
Uitgang:
[[{"a": 1, "b": "x"}], [{"a": 2, "b": "y"}]]
{"a": 1, "b": "x"}
{"a": 2, "b": "y"}