Det er, hvad der sker, hvis du dumper hele resultatsættet. Med t
tabel:
create table t (a int, b text);
insert into t (a, b) values (1,'x'), (2,'y');
Brug af Psychopg2:
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()
Output:
[[{"a": 1, "b": "x"}], [{"a": 2, "b": "y"}]]
{"a": 1, "b": "x"}
{"a": 2, "b": "y"}