Home > Back-end >  SQL Update: How to pass current value to function?
SQL Update: How to pass current value to function?

Time:11-08

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

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

I tried:

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?

CodePudding user response:

encode takes bytea as first argument. So you can use

encode(CAST (name AS bytea), 'base64')
  • Related