How to set the cursor of aiosql to use real dictionary instead of tuple of tuples?
04:31 11 Jul 2026

Here is the code:

queries = aiosql.from_str(query, 'psycopg2', mandatory_parameters=False)
result = queries.get_top_n_artists_with_most_albums(dbr.dc, n=5)
print(tuple(result))
(('Iron Maiden', 21), ('Led Zeppelin', 14), ('Deep Purple', 11), ('Metallica', 10), ('U2', 10))

result = queries.get_top_n_artists_with_most_albums(dbr.dc, n=5)
print(dict(result))
{'Iron Maiden': 21, 'Led Zeppelin': 14, 'Deep Purple': 11, 'Metallica': 10, 'U2': 10}
---- this output is not quite correct ---

How to tell aiosql that I need real dictionary output of the cursor and not tuple of tuples?

python postgresql