I have a procedure containing this code:
processStart := current_timestamp; -- run statement(s) processEnd := current_timestamp; elapsed := processEnd - processStart; raise notice 'My Statement, elapsed time: %', elapsed;
The idea is that I want to get the time it takes to execute a statement or collection of statements.
The problem is that it returns 00:00:00 for subsecond elapsed times. I really want to see milliseconds. How can i do this?
There are questions and answers about using EXTRACT and EPOCH , but it seems like a "second" level, and this is not enough for my purposes.
UPDATE
Using the @ twn08 answer, I ended up with the following solution:
I declared the following variables:
declare processStart timestamp; elapsed numeric(18,3); processFinish timestamp;
then before starting the process:
processStart := clock_timestamp();
After completing the process, 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;
it worked smoothly.
Jeremy holovacs
source share