Postgresql base64编码

时间:2014-05-16 15:09:51

标签: postgresql

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

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

显示错误

[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.

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

1 个答案:

答案 0 :(得分:9)

encode函数从bytea编码为文本。

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

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