Search code examples
databasepostgresqlblobspecial-charactersbytea

PostgreSQL: unable to save special character (regional language) in blob


I am using PostgreSQL 9.0 and am trying to store a bytea file which contains certain special characters (regional language characters - UTF8 encoded). But I am not able to store the data as input by the user.

For example :

what I get in request while debugging: <sp_first_name_gu name="sp_first_name_gu" value="ઍયેઍ"></sp_first_name_gu><sp_first_name name="sp_first_name" value="aaa"></sp_first_name>

This is what is stored in DB: <sp_first_name_gu name="sp_first_name_gu" value="\340\252\215\340\252\257\340\253\207\340\252\215"></sp_first_name_gu><sp_first_name name="sp_first_name" value="aaa"></sp_first_name>

Note the difference in value tag. With this issue I am not able to retrieve the proper text input by the user. Please suggest what do I need to do?

PS: My DB is UTF8 encoded.


Solution

  • The value is stored correctly, but is escaped into octal escape sequences upon retrieval.

    To fix that - change the settings of the DB driver or chose different different encoding/escaping for bytea.

    Or just use proper field types for the XML data - like varchar or XML.