Where in the system catalog is the function body stored?

前端 未结 2 1373
小鲜肉
小鲜肉 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:08

    For such thing I used pg_dump --schema_only [database] but now I use my specialized tool to report schema in easy to compare format:

    http://code.activestate.com/recipes/576557-dump-postgresql-db-schema-to-text/

    Of course it reads function/procedure bodies/

    0 讨论(0)
  • 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;
    
    0 讨论(0)
提交回复
热议问题