自定函數
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函數體的開始和結束