timescaledb-toolkit
timescaledb-toolkit copied to clipboard
time_weight average with null values gives an error
Relevant system information:
- OS: macOS Monterey 12.0.1
- PostgreSQL version (output of
SELECT version();
): 14.0 - TimescaleDB Toolkit version (output of
\dx timescaledb_toolkit
inpsql
): 1.4 - Installation method: docker
Describe the bug When performing a time weighted average on a bucket beginning with null data, the query fails and gives an error.
To Reproduce
create table example (
time timestamptz,
val int
);
insert into example values
('2021-11-20 9:00', null),
('2021-11-20 9:10', null),
('2021-11-20 9:20', 1.0);
select
time_bucket('60 minute', time) as _time,
average(time_weight('LINEAR', time, val))
from example
group by time_bucket('60 minute', time);
Expected behavior It returns an average of 1.
Actual behavior Receive an error upon running the query:
SQL Error [XX000]: ERROR: returned Datum was NULL
Where: extension/src/time_weighted_average.rs:109:1