1

I have a pg_dump of a table that contains a column of type bytea. It is a long string like: \\x4e696365206d7573696361...

Normally in SQL I would use a simple:

SELECT user_id,
       encode(text_column::bytea, 'escape')
FROM posts
LIMIT 10

And that provides the original text.

How can I convert this in Python? I've been trying .encode/.decode/base64encode etc but no luck.

LittleBobbyTables
  • 4,361
  • 9
  • 38
  • 67

1 Answers1

2

Ok, following to your example its simple hex representation.

>>> '\\x48414e44203330'.lstrip('\\x').decode('hex')
'HAND 30'
sKwa
  • 889
  • 5
  • 11