I have a procedure that contains code like this:
processStart := current_timestamp;
-- run statement(s)
processEnd := current_timestamp;
elapsed := processEnd - processStart;
raise notice 'My Statement, elapsed time: %', elapsed;
The idea is, I want to get the amount of time it takes for a statement or collection of statements to run.
The problem is, this returns 00:00:00
for subsecond elapsed times. I really want to see the milliseconds. How can I do this?
There's questions and answers about using EXTRACT
and EPOCH
, but this seems to be at the "second" level, and that is not granular enough for my purposes.
UPDATE
Using @twn08's answer, I ultimately arrived at the following solution:
I declared the following variables:
declare
processStart timestamp;
elapsed numeric(18,3);
processFinish timestamp;
then, prior to starting the process:
processStart := clock_timestamp();
after the process was finished, I ran this:
processFinish := clock_timestamp();
elapsed := cast(extract(epoch from (processFinish - processStart)) as numeric(18,3));
raise notice 'My Statement, elapsed time: % ms', elapsed;
this worked swimmingly.
SELECT EXTRACT(MILLISECONDS FROM Now());
– Territerrible