user1781186
user1781186

Reputation:

Decode python tuple

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

Answers (1)

Peter Eisentraut
Peter Eisentraut

Reputation: 36729

There is no need to do any decoding. Psycopg does that for you. Remove all that decode business.

Upvotes: 2

Related Questions