0
select encode('नमस्त', 'base64');

        encode        
──────────────────────
 4KSo4KSu4KS44KWN4KSk


select decode('4KSo4KSu4KS44KWN4KSk','base64');

              decode              
──────────────────────────────────
 \xe0a4a8e0a4aee0a4b8e0a58de0a4a4

Why does not this return the Hindi text?

collate: en_US.UTF-8 Ctype: en_US.UTF-8

0
2

The documentation tells you what exactly decode() returns:

Function                          Return Type   Description
-------------------------------------------------------------------------------
decode(string text, format text)  bytea         Decode binary data from textual 
                                                representation in string.

'\xe0a4a8e0a4aee0a4b8e0a58de0a4a4' is the bytea output. You need an additional call of convert_from() to turn this back to text:

SELECT convert_from(decode(encode('नमस्त', 'base64'), 'base64'), 'utf8');
 convert_from 
──────────────
 नमस्त
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.