我想跟踪函数内的执行时间。例如,我有以下状态跟踪表:
CREATE TABLE status_table
(
run_id numeric NOT NULL,
start_ts timestamp(6) without time zone NOT NULL,
end_ts timestamp(6) without time zone NOT NULL
)
WITH (
OIDS=FALSE
)
DISTRIBUTED RANDOMLY;
我有以下示例函数,它使用PG_SLEEP(5)来模拟我的函数实际执行的操作:
CREATE OR REPLACE FUNCTION wrapper_func(p_run_id numeric)
RETURNS numeric AS
$BODY$
Declare
tmp_start_ts timestamp(6) without time zone;
tmp_end_ts timestamp(6) without time zone;
BEGIN
tmp_start_ts := CURRENT_TIMESTAMP;
PERFORM PG_SLEEP(5);
tmp_end_ts := CURRENT_TIMESTAMP;
INSERT INTO status_table (run_id,start_ts,end_ts) VALUES (p_run_id,tmp_start_ts,tmp_end_ts);
RETURN 0;
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
然后我调用了这个函数三次,每次调用之间等待大约20秒:
SELECT * FROM wrapper_func(1);
SELECT * FROM wrapper_func(2);
SELECT * FROM wrapper_func(3);
但是,当我在status_table中查看结果时,时间戳都是一样的:
SELECT * FROM status_table ORDER BY run_id;
run_id|start_ts|end_ts
1|2015-01-18 17:54:43.641294|2015-01-18 17:54:43.641294
2|2015-01-18 17:54:43.641294|2015-01-18 17:54:43.641294
3|2015-01-18 17:54:43.641294|2015-01-18 17:54:43.641294
有人可以指出我做错了什么或其他方法来实现这个目标吗?
由于
答案 0 :(得分:4)