50

I have a fairly short (14-byte) bytea data column in my database. I would like to print it as a hexadecimal string.

How do I do that?

Zoltán
  • 21,321
  • 14
  • 93
  • 134

1 Answers1

94

Based on this answer, I found my solution to be

SELECT encode(my_column::bytea, 'hex') FROM my_table;
Nicholas Shanks
  • 10,623
  • 4
  • 56
  • 80
Zoltán
  • 21,321
  • 14
  • 93
  • 134
  • @Zero are you using it on PostgreSQL or another database? Could you post the command you're using and the exact and complete error message? – Zoltán Feb 09 '15 at 10:04
  • `select ... encode(k1.keyword, 'hex')`: `ERROR: function encode(character varying, unknown) does not exist` – Chloe Aug 23 '16 at 19:42
  • 2
    In pg 9.6.1, I had to coerce the column to the bytea type to get this to work: `SELECT encode(my_column::bytea, 'hex') FROM my_table;` – acj Dec 30 '16 at 20:53