qj_zhai 发表于 2011-12-23 14:40

postgresql的"函数"怎么导出脚本

postgresql的"函数"怎么导出脚本,因为我创建库的时候,他默认的函数那项是空的,但是我在别的服务器里创建的就默认就753个函数.
因为没有函数,我执行一些脚本就报错.但我又不知道缺少哪几个函数.哪位DX帮帮忙,有什么比较简便的方法把函数创建过去阿

renxiao2003 发表于 2011-12-24 14:20

用pgadmin3可以看到原始SQL

osdba 发表于 2011-12-29 21:06

两种方法:
方法一:查询pg_proc:

osdba=# select prosrc from pg_proc where proname='get_username';
                         prosrc                        
--------------------------------------------------------

declare
    ret text;
begin
      SELECT name into ret from tang01 where id=userid;
      return ret;
end;

(1 row)

方法二:调用pg_catalog.pg_get_functiondef函数:
osdba=# select pg_get_functiondef('get_username'::regproc);
                     pg_get_functiondef                     
----------------------------------------------------------------
CREATE OR REPLACE FUNCTION public.get_username(userid integer)
RETURNS text
LANGUAGE plpgsql
AS $function$
declare
    ret text;
begin
      SELECT name into ret from tang01 where id=userid;
      return ret;
end;
$function$

sychangchun 发表于 2012-01-30 10:31

从pgadmin里存出来。

renxiong1984 发表于 2015-09-18 17:12

回复 3# osdba


    大哥,postgresql数据库,使用sql命令怎么导出table建表语句,一定要是可执行是sql或存储过程之类的
页: [1]
查看完整版本: postgresql的"函数"怎么导出脚本