I'm starting a PostgreSQL project, after many years with Sybase and SQL Server, and am new to it's quirks, but so far have been impressed.
I've written a small function that returns OUT parameters. I pass in a clear password and the function returns the encrypted password and a salt. Here it is:
CREATE OR REPLACE FUNCTION iSecGenPwdSalt(pwdin text, out salt text, out userpassword text)
AS
$BODY$
DECLARE
BEGIN
-- Generate a salt...
salt = gen_salt('bf', 10);
-- Now generate the password hash...
userpassword = crypt(pwdin, salt);
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION iSecGenPwdSalt(text, out text , out text ) OWNER TO postgres;
I'd like to call this function within a trigger and use the values to populate the password and salt columns I have, but I can't fathom the syntax. I've tried multiple variations ona theme but I'm still having problems.
select salt, userpassword from iSecGenPwdSalt('mymagicpassword');
Returns it's results beautifully, so I'd like to call this function and get the results into a pair of variables in a trigger so I can assign the values.
Here's my code:
SELECT usersalt=salt, userpwd=userpassword
FROM iSecGenPwdSalt(NEW.systemuserpassword);
The error I get is thus:
ERROR: query has no destination for result data HINT: If you want to discard the results of a SELECT, use PERFORM instead. CONTEXT: PL/pgSQL function "isec_trg_systemuser" line 13 at SQL statement
So simply assigning a pair of variables to a resultset derived from OUT parameters in a trigger is causing me grief.