Postgre数据库自定义函数

为君一笑 提交于 2019-12-05 11:49:18

自定函数

1、查询函数:

     select prosrc from pg_proc where proname='test'  test 为函数名。

2、删除函数:

     drop function test(anyelement,anyelement,numeric)  test 为函数名。

3、定义数据库函数: 

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!