Postgresql base64编码

Pra*_*T.P 6 postgresql

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

 select encode(cast(est_name as text),'base64') from establishments;
Run Code Online (Sandbox Code Playgroud)

它显示错误

[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.
Run Code Online (Sandbox Code Playgroud)

哪里错了?请帮忙.提前致谢

Clo*_*eto 11

encode函数从bytea编码为文本.

select encode(est_name::bytea, 'base64') 
from establishments;
Run Code Online (Sandbox Code Playgroud)

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


小智 7

字符串的编码解码示例

select encode('mystring'::bytea, 'base64');
select convert_from(decode('bXlzdHJpbmc=', 'base64'), 'UTF8');
Run Code Online (Sandbox Code Playgroud)

从表中的现有列

select encode(mycolum::bytea, 'base64') from mytable;
Run Code Online (Sandbox Code Playgroud)