Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I print bytea data as a hexadecimal string in PostgreSQL / pgAdmin III?

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?

like image 833
Zoltán Avatar asked Apr 17 '13 09:04

Zoltán


People also ask

What is datatype Bytea?

The bytea data type allows the storage of binary strings or what is typically thought of as “raw bytes”. Materialize supports both the typical formats for input and output: the hex format and the historical PostgreSQL escape format. The hex format is preferred.

Can we store bytes in PostgreSQL?

PostgreSQL provides two distinct ways to store binary data. Binary data can be stored in a table using the data type bytea or by using the Large Object feature which stores the binary data in a separate table in a special format and refers to that table by storing a value of type oid in your table.


1 Answers

Based on this answer, I found my solution to be

SELECT encode(my_column::bytea, 'hex') FROM my_table; 
like image 199
Zoltán Avatar answered Oct 03 '22 03:10

Zoltán