Reputation:
I am fetching a number of rows from a PostgreSQL database using Psycopg2. Everything is working fine, except the encoding. The database is encoded in UTF-8.
This returns the result I want:
cur.execute("SELECT * FROM table")
row = cur.fetchone().decode('utf-8')
But how do I do the same for cur.fetchall()
? I tried looping over the returned tuple but that didn't work.
EDIT:
Here's my decoding function that gives 'tuple' object has no attribute 'decode'
in Django.
def dec(tup):
res = []
for row in tup:
res.append(row.decode('utf-8'))
return res
Upvotes: 0
Views: 1887
Reputation: 36729
There is no need to do any decoding. Psycopg does that for you. Remove all that decode
business.
Upvotes: 2