average multiplied
by the elapsed time.
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
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Calculate the integral from a TimeWeightSummary
average multiplied
by the elapsed time.
-- Create a table to track irregularly sampled storage usage
CREATE 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 used
SELECT
integral(time_weight('LOCF', ts, storage_bytes), 'hours')
FROM
user_storage_usage;
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 Postgres |
| Column | Type | Description |
|---|---|---|
| integral | DOUBLE PRECISION | The time-weighted integral. |