postgres中查看函數創建語句

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=# 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章