18

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

2 Answers 2

24

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

Sign up to request clarification or add additional context in comments.

6 Comments

It showing error: [SQL]select encode(est_name::bytea, 'base64') from establishments; [Err] ERROR: invalid input syntax for type bytea The actual field type is character_varying(250)
@Pradeep What is the type of est_name? Show sample data
The field is varchar (250) and sample data below : Gift Express, Mozart Musical Instruments, Ralph Lauren, Toscana, Damas, Atrium Cafe, Tanagra etc
@Pradeep Works for me. Is the etc the end of the data or it means there is more? Add a few lines of the data to the question.
I am using 9.2 version
|
14

Encode decode examples for string

select encode('mystring'::bytea, 'base64');
select convert_from(decode('bXlzdHJpbmc=', 'base64'), 'UTF8');

From existing column in table

select encode(mycolum::bytea, 'base64') from mytable;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.