Where in the system catalog is the function body stored?

前端 未结 2 1377
小鲜肉
小鲜肉 2021-01-24 22:56

I am trying to build a documentation system for my database and I would like to include the source of my functions and triggers.

I managed to find all of the metadata on

2条回答
  •  遥遥无期
    2021-01-24 23:23

    Use the function pg_get_functiondef() to get the complete function definition:

    SELECT pg_get_functiondef('my_schema.my_func(int)'::regprocedure)
    

    The cast to the object identifier regprocedure is the simplest way to get the oid of your function, which you feed to the above function.

    The manual on pg_catalog.pg_proc:

    For compiled functions, both built-in and dynamically loaded, prosrc contains the function's C-language name (link symbol). For all other currently-known language types, prosrc contains the function's source text.

    To retrieve the function body only:

    SELECT prosrc 
    FROM   pg_proc
    WHERE  oid = 'my_schema.my_func(int)'::regprocedure;
    

提交回复
热议问题