Skip to content
Advertisement

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:

Unfortunately, the intervals of timestamp are not regular, and I wanted to do something like a numerical integration (using trapezoidal rule or something).

Advertisement

Answer

You can use lag() and sums. Something like this:

This does the integral using seconds for the horizontal axis.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement