PostgreSQL 9.6 – GRANT Requirements for Stored Procedure

postgresql

I have a role that will execute a stored procedure (function) to update a table.
I give the user acccess to the role, and the role execute on the stored procedure.
Do I also have to give the role update on the table?
Thanks

Best Answer

You have three options. You can grant update on the table to the role. You can grant update on the table to the user. Or you can do neither of those and create the function with the "SECURITY DEFINER" option.

In the last case, then the user will be able to update the table via the function, but will not be able to update the table outside of the function.