'Is there a way of computing numerical integration on PostgreSQL?
I've got a table with the following columns: timestamp, name and activePower. I wanted to compute power consumption based on that and add it to a Grafana line chart.
Right now, what I'm doing is a cumulative sum, like the following:
SELECT
"timestamp" as time,
"name", sum("activePower")
OVER(
PARTITION BY "name"
ORDER BY "timestamp"
) AS cumulative_sum
FROM main
Unfortunately, the intervals of timestamp are not regular, and I wanted to do something like a numerical integration (using trapezoidal rule or something).
Solution 1:[1]
Although is marked as correct, the second line:
lag(activePower) over (partition by name order by activePower)
Should be ordered by timestamp too.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nuno Vivas |
