How to print functions and triggers sourcecode in postgresql? please let me know if any one know the query to display the function, triggers source code.
Since Version: psql (9.6.17, server 11.6)
I have tried all of above answer but For me
postgres=> \sf jsonb_extract_path_text
CREATE OR REPLACE FUNCTION pg_catalog.jsonb_extract_path_text(from_json jsonb, VARIADIC path_elems text[])
RETURNS text
LANGUAGE internal
IMMUTABLE PARALLEL SAFE STRICT
AS $function$jsonb_extract_path_text$function$
postgres=> \df+
ERROR: column p.proisagg does not exist
LINE 6: WHEN p.proisagg THEN 'agg'
^
HINT: Perhaps you meant to reference the column "p.prolang".
df seems not working for me.
For function:
you can query the pg_proc view , just as the following
select proname,prosrc from pg_proc where proname= your_function_name;
Another way is that just execute the commont \df
and \ef
which can list the functions.
skytf=> \df
List of functions
Schema | Name | Result data type | Argument data types | Type
--------+----------------------+------------------+------------------------------------------------+--------
public | pg_buffercache_pages | SETOF record | | normal
skytf=> \ef pg_buffercache_pages
It will show the source code of the function.
For triggers:
I dont't know if there is a direct way to get the source code. Just know the following way, may be it will help you!
skytf=> select tgrelid from pg_trigger where tgname='insert_tbl_tmp_trigger'; tgrelid --------- 26599 (1 row)
skytf=> select oid,relname from pg_class where oid=26599; oid | relname -------+----------------------------- 26599 | tbl_tmp (1 row)
skytf=> \d tbl_tmp
It will show you the details of the trigger of the table . Usually a trigger uses a function. So you can get the source code of the trigger function just as the above that I pointed out !