integral()
Calculate the integral from a TimeWeightSummary
Since 1.15.0
Calculate the integral, or the area under the curve formed by the data points. Equal to average multiplied
by the elapsed time.
Samples
Section titled “Samples”Create a table to track irregularly sampled storage usage in bytes, and get the total storage used in byte-hours. Use the ‘last observation carried forward’ interpolation method:
-- Create a table to track irregularly sampled storage usageCREATE TABLE user_storage_usage(ts TIMESTAMP, storage_bytes BIGINT);INSERT INTO user_storage_usage(ts, storage_bytes) VALUES ('01-01-2022 00:00', 0), ('01-01-2022 00:30', 100), ('01-01-2022 03:00', 300), ('01-01-2022 03:10', 1000), ('01-01-2022 03:25', 817);
-- Get the total byte-hours usedSELECT integral(time_weight('LOCF', ts, storage_bytes), 'hours')FROM user_storage_usage;Arguments
Section titled “Arguments”The syntax is:
integral( tws TimeWeightSummary [, unit TEXT]) RETURNS DOUBLE PRECISION| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| tws | TimeWeightSummary | - | ✔ | The input TimeWeightSummary from a time_weight() call |
| 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 PostgreSQL |
Returns
Section titled “Returns”| Column | Type | Description |
|---|---|---|
| integral | DOUBLE PRECISION | The time-weighted integral. |