1、比如创建一个函数
postgres=# create function f_ret(id int) returns int as $$
postgres$# declare
postgres$# begin
postgres$# return id+1;
postgres$# end;
postgres$# $$ language plpgsql strict;
CREATE FUNCTION
postgres=#
2、查询f_ret函数的定义
postgres=# select prosrc from pg_proc where proname ='f_ret';
-[ RECORD 1 ]--------
prosrc | +
| declare +
| begin +
| return id+1;+
| end; +
|
postgres=#
3、pg_proc的结构
postgres=# \d pg_proc
Table "pg_catalog.pg_proc"
Column | Type | Collation | Nullable | Default
-----------------+--------------+-----------+----------+---------
proname | name | | not null |
pronamespace | oid | | not null |
proowner | oid | | not null |
prolang | oid | | not null |
procost | real | | not null |
prorows | real | | not null |
provariadic | oid | | not null |
protransform | regproc | | not null |
prokind | "char" | | not null |
prosecdef | boolean | | not null |
proleakproof | boolean | | not null |
proisstrict | boolean | | not null |
proretset | boolean | | not null |
provolatile | "char" | | not null |
proparallel | "char" | | not null |
pronargs | smallint | | not null |
pronargdefaults | smallint | | not null |
prorettype | oid | | not null |
proargtypes | oidvector | | not null |
proallargtypes | oid[] | | |
proargmodes | "char"[] | | |
proargnames | text[] | | |
proargdefaults | pg_node_tree | | |
protrftypes | oid[] | | |
prosrc | text | | not null |
probin | text | | |
proconfig | text[] | | |
proacl | aclitem[] | | |
Indexes:
"pg_proc_oid_index" UNIQUE, btree (oid)
"pg_proc_proname_args_nsp_index" UNIQUE, btree (proname, proargtypes, pronamespace)
postgres=#
还要一种更方便的方式
\sf[+] FUNCNAME show a function's definition
postgres=# \sf f_ret
CREATE OR REPLACE FUNCTION public.f_ret(id integer)
RETURNS integer
LANGUAGE plpgsql
STRICT
AS $function$
declare
begin
return id+1;
end;
$function$
postgres=#