timescale / timescaledb-toolkit

Extension for more hyperfunctions, fully compatible with TimescaleDB and PostgreSQL 📈
https://www.timescale.com
Other
385 stars 47 forks source link

[Feature]: Have LTTB return all columns #810

Open deanna-abrams opened 2 months ago

deanna-abrams commented 2 months ago

What problem does the new feature solve?

LTTB is a very useful function that downsamples data. However, it only returns the time and the value from the downsampled rows. It would be very useful to have access to the values of other columns from the downsampled rows.

What does the feature do?

perhaps something like

SELECT
    grouping_column,
    (lttb_data).time,
    (lttb_data).value,
    (lttb_data).non_grouping_column_value
FROM (
    SELECT
      grouping_column,
      UNNEST(lttb(time, float_value, $<nPoints>)) AS lttb_data
    FROM hypertable
    GROUP BY grouping_column
)

Implementation challenges

No response