postgresql循环中的计时

时间:2018-03-08 21:48:47

标签: postgresql function loops timing

我在postgres中创建了一个函数,它在循环中有一个查询,迭代n次。我想知道每次迭代的执行时间。 (这里给出的是一个类似的功能)

' \定时'将给出函数调用执行时间,但不完全是循环迭代时间。

create function somefunction()
return something
---
Declare
--
--
BEGIN
for somevalue in something
loop 
insert into table_name
select name,id from sales where name = "John"; --want to know the execution time of this statement
end loop;
return 
END
$$ language plpgsql volatile;

我也尝试在循环中插入语句之前放置EXPLAIN ANALYZE(如下所示)

loop
EXPLAIN ANALYZE insert into table_name
select name,id from sales where name = "John";
end loop;

给出此错误 - 错误:查询没有结果数据的目的地

1 个答案:

答案 0 :(得分:1)

您可能希望将Sub main() Dim cell As Range Dim validateSht As Worksheet: Set validateSht = Worksheets("validated_status") With Worksheets("To update") With .Range("H1:H" & .Cells(.Rows.Count, "A").End(xlUp).Row) .AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Worksheets("validated_status").Range("A1"), Unique:=True validateSht.Range("B1").value = "validated_status" For Each cell In validateSht.Range("A2", validateSht.Cells(validateSht.Rows.Count, "A").End(xlUp)) Select Case True Case Application.WorksheetFunction.CountIfs(.Cells, cell.value, .Offset(, 1), "pending") > 0 cell.Offset(, 1).value = "pending" Case Application.WorksheetFunction.CountIfs(.Cells, cell.value, .Offset(, 1), "cancelled") > 0 cell.Offset(, 1).value = "rejected" Case Application.WorksheetFunction.CountIfs(.Cells, cell.value, .Offset(, 1), "complete") > 0 cell.Offset(, 1).value = "approved" End Select Next End With End With End Sub 的结果存储到记录或字符变量变量中,以便稍后使用该变量查看结果。

这样的事情:

EXPLAIN ANALYZE

然后,您现在可以使用该变量通过使用EXPLAIN ANALYZE insert into table_name select name,id from sales where name = "John" INTO result; 或将其插入新表或任何您喜欢的内容来查看执行时间