Postgre数据库自定义函数

                                                                                                              自定函数

1、查询函数:

    

 select prosrc from pg_proc where proname='test'

参数说明 : test 为函数名。

2、删除函数:

     

1  drop function test(anyelement,anyelement,numeric)

 参数说明 : test 为函数名。

3、定义数据库函数: 

 

1  create or replace function calculate_speed(end_time anyelement,begin_time anyelement,length numeric) RETURNS numeric  as
2   $$
3      declare
4      total_second numeric;
5      begin
6             select extract(epoch from((end_time::timestamp - begin_time)))/3.6 into total_second;
7             return round(length::numeric/total_second::numeric,3);
8      end;
9   $$ LANGUAGE plpgsql;

 参数说明:calculate_speed代表自定义函数名称     anyelement numeric参数类型   begin end函数体的开始和结束

原文地址:https://www.cnblogs.com/dongl961230/p/11923302.html