Postgresql base64 编码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23698719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:27:10  来源:igfitidea点击:

Postgresql base64 encode

postgresql

提问by Pradeep.T.P

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

我需要将 db 值转换为 base64encode。我试过:

 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

我错在哪里?请帮忙。提前致谢

回答by Clodoaldo Neto

The encodefunction encodes from bytea to text.

encode函数从 bytea 编码为文本。

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

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

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