integral, but allows an accurate calculation across interval bounds when data has been bucketed
into separate time intervals, and there is no data point precisely at the interval bound. For example, this is useful in
a window function.
Values from the previous and next buckets are used to interpolate the values at the bounds, using the same interpolation
method used within the TimeWeightSummary itself.
Equal to interpolated_average multiplied by the elapsed time.
Arguments
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| tws | TimeWeightSummary | - | ✔ | The input TimeWeightSummary from a time_weight() call |
| start | TIMESTAMPTZ | - | ✔ | The start of the interval which the time-weighted integral should cover (if there is a preceding point) |
| interval | INTERVAL | - | ✔ | The length of the interval which the time-weighted integral should cover |
| prev | TimeWeightSummary | NULL | The TimeWeightSummary from the prior interval, used to interpolate the value at start. If NULL, the first timestamp in tws is used for the starting value. The prior interval can be determined from the Postgres lag() function | |
| next | TimeWeightSummary | NULL | The TimeWeightSummary from the next interval, used to interpolate the value at start + interval. If NULL, the last timestamp in tws is used for the starting value. The next interval can be determined from the Postgres lead() function | |
| unit | TEXT | second | The unit of time to express the integral in. Can be microsecond, millisecond, second, minute, hour, or any alias for those units supported by Postgres |
Returns
| Column | Type | Description |
|---|---|---|
| integral | DOUBLE PRECISION | The time-weighted integral for the interval (start, start + interval), computed from the TimeWeightSummary plus end points interpolated from prev and next |