Search code examples
databasepostgresqlstored-proceduresnpgsql

Procedure to get the parameters and result type of a PostgreSQL stored procedure?


What is the procedure to get the parameter and return types of a stored procedure? (Google is of no help :-( ).

Something along the lines of:

using (var conn = new Npgsql.NpgsqlConnection(connectionString: c))
        {
            conn.Open();

            using (var cmd = con.CreateCommand())
            {
                cmd.CommandText = "\"GetAllDx\"";
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.GETPARAMETERS()????????

            }
        }

PostgreSQL 9.5
Npgsql 3.0.5


Solution

  • Here is one way:

    SELECT pg_get_function_result(oid), pg_get_function_arguments(oid)
    FROM pg_proc
    WHERE proname = 'GetAllDx'
    

    You may also find this useful (although this query returns more than you've asked for):

    SELECT oid::regprocedure FROM pg_proc WHERE proname = 'GetAllDx'