Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql base64 encode

Tags:

postgresql

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

like image 244
Pradeep.T.P Avatar asked May 16 '14 15:05

Pradeep.T.P


People also ask

What is encoding in PostgreSQL?

The character set support in PostgreSQL allows you to store text in a variety of character sets (also called encodings), including single-byte character sets such as the ISO 8859 series and multiple-byte character sets such as EUC (Extended Unix Code), UTF-8, and Mule internal code.

What is Bytea?

The bytea data type allows the storage of binary strings or what is typically thought of as “raw bytes”. Materialize supports both the typical formats for input and output: the hex format and the historical PostgreSQL escape format. The hex format is preferred.

Can we convert image URL to Base64?

With elmah. io's free image to Base64 encoder, it's easy to copy and paste markup or style for exactly your codebase. Simply drag and drop, upload, or provide an image URL in the controls above and the encoder will quickly generate a Base64 encoded version of that image.


1 Answers

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;
like image 78
Jeremy Busk Avatar answered Sep 19 '22 22:09

Jeremy Busk