Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL Update: How to pass current value to function?

I want to base64-encode all names in a table. (PostgreSql)

What does seem logical to me, doesn’t work.

I tried:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

update person
set name = encode(name, 'base64');

throws an error:
ERROR: function encode(character varying, unknown) does not exist

SELECT encode('test, 'base64');
-> works without problems

How can I pass the value of ‘name’ to the function?

>Solution :

encode takes bytea as first argument. So you can use

encode(CAST (name AS bytea), 'base64')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading