How to get the list of functions in database in PostgreSQL along with its parameters?

后端 未结 2 841
野性不改
野性不改 2021-01-21 05:05

I have a database which has over 1000 functions. I want to GRANT execution permission to certain users. I can\'t do it manually, therefore I want to get a list of functions and

2条回答
  •  野的像风
    2021-01-21 05:34

    You should use pg_get_function_arguments(func_oid). Dynamic GRANT must be executed in anonymous code block or function (change my_schema and my_username to actual values):

    do $$
    declare
        funcdef text;
    begin
        for funcdef in
            select format('%s.%s (%s)', 
                nspname, proname, pg_get_function_arguments(p.oid))
            from pg_proc p
            join pg_namespace n on pronamespace = n.oid
            where nspname = 'my_schema' 
            and not proisagg
        loop
            execute format ('GRANT EXECUTE ON FUNCTION %s TO my_username', funcdef);
        end loop;
    end $$;
    

提交回复
热议问题