I'm new to PostgreSQL and any other databases. I was trying to create a function (we are on version 9.6) that can select a temporary hashed password from a list and update the table and return the non hashed value, for example:
CREATE OR REPLACE FUNCTION updatePassword(_id varchar ) RETURNS varchar AS
$do$
BEGIN
-- randomly select one
-- passowrd1, hashedPasswordValue1
-- password2, hashedPasswordValue2
-- passowrd3, hashedPasswordValue3
-- password4, hashedPasswordValue4
UPDATE accounts
SET "password" = **hashedPasswordValue4**, last_password_change = NOW()
WHERE id = _id ;
RETURN 'The password has been updated successfully to **password4**';
END;
$do$ LANGUAGE plpgsql;
Or if it's no possible what alternatives are there to do this?