1

I'm trying to run the sha256 function in HeidiSQL, but I'm getting that function doesn't exist. The query is the following:

UPDATE db_name.users 
SET db_name.users.password = sha256(db_name.users.password)
WHERE user_id = (secret_numeric_id);

Is anything I'm doing wrong about the query or is HeidiSQL itself?

Here's the error message:

ERROR: function sha256(character varying) does not exist.
LINE 2: SET db_name.users.password = sha256(db_name.users.password)

HINT: No function matches in name and argument types. It may be necessary to add explicit type conversion.

EDIT

Running the following query:

UPDATE db_name.users 
SET db_name.users.password = sha256(convert_to(db_name.users.password), 'LATIN1')
WHERE user_id = (secret_numeric_id);

I'm getting the same error message, with different param type:

ERROR: function sha256(bytea) does not exist.
LINE 2: SET db_name.users.password = sha256(db_name.users.password)

HINT: No function matches in name and argument types. It may be necessary to add explicit type conversion.
Álvaro
  • 385
  • 5
  • 15
  • What is the _exact_ error message you get (please **[edit]** your question, don't add additional information as comments) –  Feb 09 '23 at 11:07
  • I added the error message. I haven't add an image because it is in Spanish – Álvaro Feb 09 '23 at 11:11
  • 2
    Well, `sha256()` expects a `bytea` value, not a varchar. And it also returns a `bytea` so you wouldn't be able to assign the result to a `varchar` column. Btw: `db_name` in your SQL refers to a _schema_ not a "database". –  Feb 09 '23 at 11:17
  • You're right about the param type, thanks. But I'm getting the same error making a conversion. Also, `db_name` is the database. I have edited my question – Álvaro Feb 09 '23 at 11:26
  • 1
    `db_name` can't be the "database" as that would be invalid SQL. –  Feb 09 '23 at 11:27
  • @a_horse_with_no_name please, could you add your comment as an answer to mark as accepted? It have helped me a lot! – Álvaro Feb 09 '23 at 13:14

0 Answers0