Using PostgreSQL 8.4, how to convert bytea to text value in postgres?
45
votes
3
answers
197187
views
In my application I insert data in database using C code, since the strings I receive from an untrusted source I have escaped them using
PQescapeByteaConn
of libpq library. Which is working perfectly fine i.e. results in Octet format String. See below example,
Input String : \n\t\f\b\p\k\j\l\mestPrepared
Output String : \\012\\011\\014\\010pkjlmestPrepared
Output String is inserted in the database. Now I retrieve that data from the database in a java code using JDBC. How I can unescape the string back to its original value ?
I thought of two possible approaches,
1. Change the database retrieval query and pass this field to any String manipulation function of postgres i.e. which can convert bytea to text.
2. Do the decoding in Java code.
I can understand that the approach 1 will be more efficient. I have tried almost all the functions listed here but nothing is working. Please Help!!
I am using version 8.4 of postgres on a linux machine.
Asked by Amit
(591 rep)
Nov 14, 2013, 10:20 AM
Last activity: Dec 30, 2020, 10:47 PM
Last activity: Dec 30, 2020, 10:47 PM