Postgresql base64 encode

坚强是说给别人听的谎言 提交于 2020-11-28 04:56:13

问题


I need to convert a db value into base64encode. I tried:

 select encode(cast(est_name as text),'base64') from establishments;

It showing error

[SQL]select encode(string(cast(est_name as text)),'base64') from establishments;

[Err] ERROR:  function string(text) does not exist
LINE 1: select encode(string(cast(est_name as text)),'base64') from ...
                      ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

Where I am wrong? please help. thanks in advance


回答1:


The encode function encodes from bytea to text.

select encode(est_name::bytea, 'base64') 
from establishments;

http://www.postgresql.org/docs/current/static/functions-binarystring.html#FUNCTIONS-BINARYSTRING-OTHER



来源:https://stackoverflow.com/questions/23698719/postgresql-base64-encode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!