I'm trying to create a query that will return data in this format:
id | time | value |
---|---|---|
1 | 1 | 2.5 |
1 | 2 | 3.5 |
1 | 3 | 6.4 |
2 | 1 | 8.3 |
2 | 2 | 8.5 |
I'm using Timescaledb and wish to use one of their downsampling functions for each unique id
select
id,
asap_smooth(time, value, 80)
from
data
group by
id
Where the asap_smooth
aggregate function returns a custom datatype that can be unnested without the id into the following format:
SELECT * FROM unnest(
(SELECT asap_smooth(time, value, 80)
FROM data));
time | value |
---|---|
1 | 2.5 |
2 | 3.5 |
3 | 6.4 |
Is there anyway to get each row tagged with the id it belongs to? I've tried this query however I can't seem to unpack the record type into their own columns:
select
id,
unnest ((select asap_smooth(time, value, 80))) t
from
data
group by
id
id | t |
---|---|
1 | {1,2.5} |
1 | {2,3.5} |
1 | {3,6.4} |
2 | {1,8.3} |
2 | {2,8.5} |