Convert Bytea to text in PostgreSQL
One of my friend asked me a question that , He has stored XML data in a table with bytea column and he want to get the data back as XML. We can use the “encode function” to get the same.
postgres=# create table test(
name bytea);
CREATE TABLE
postgres=# insert into test values (”);
INSERT 0 1
postgres=# insert into test values (‘Srinivas’);
INSERT 0 1
postgres=# select * from test;
name
————————–
\x3c584d4c3e3c2f584d4c3e
\x5372696e69766173
(2 rows)
postgres=#
postgres=# select encode(name,’escape’) from test;
encode
————-
Srinivas
(2 rows)
very simple! thanks!
LikeLike