Search code examples
postgresqlpermissions

What permissions do I need to grant a user that wants to view the definition of a stored procedure, function, view or trigger?


If I want to allow a user to see the definition of a database object that they are not allowed to select or execute how would I do that?


Solution

  • With a few exceptions like pg_authid, all PostgreSQL metadata tables are readable by PUBLIC, that is everybody. In particular, you can get the function definition with

    SELECT prosrc
    FROM pg_proc
    WHERE proname = 'myfunc';
    

    (The source of new-style SQL functions would be stored in parsed form in prosqlbody.)