postgresql - Rerturn returning ID from function -
I'm basically trying to return the updated ID to the following function. The following is a simplified version of my code:
create confirmation user (_token varchar (255)) integer AS $$ Return to Return (Update User has been confirmed = true Where _token = token returning id)); End; $$ LANGUAGE plpgsql; What's wrong with this?
I do not think you can return the value in such a way that you can store it in a variable And then return to that variable:
confirm the function user (_token varchar (255)) declare integer $$ declare _id integer; BEGIN Update user to SET has been verified = true, where _token = token returning id _id; Return _id; End; $$ LANGUAGE plpgsql; But for this you do not need a PL / pgSQL function. A plain SQL function will work correctly:
Confirm functionUserver (_token varchar (255)) Returns as integer AS $$ UPDATE users have been set up confirmed = True where _token = token returning id $$ LANGUAGE SQL; But you have to make sure that token is unique, else it will fail.
Comments
Post a Comment