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

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值