I'm trying to use AWS Timestream as the datasource for a POC of a stock analytics application. I plan to save stock data at the lowest interval available in the DB and then query the desired timeframes.
What I tried so far is to use window functions.
But I just can't get it to work. I already tried the following queries:
SELECT BIN(time, 15m) as binned_timestamp,
max(measure_value::double) as high,
first_value(measure_value::double) over (partition by BIN(time, 15m)) as open,
last_value(measure_value::double) over (partition by BIN(time, 15m)) as close,
min(measure_value::double) as low
FROM mydb.mytable
GROUP BY BIN(time, 15m),
first_value(measure_value::double),
last_value(measure_value::double)
ORDER BY binned_timestamp
Results in
line 3:2: '"first_value"(measure_value::double) OVER (PARTITION BY "BIN"(time, INTERVAL '15' MINUTE))' must be an aggregate expression or appear in GROUP BY clause
SELECT BIN(time, 15m) as binned_timestamp,
max(measure_value::double) as high,
first_value(measure_value::double) over (partition by BIN(time, 15m)) as open,
last_value(measure_value::double) over (partition by BIN(time, 15m)) as close,
min(measure_value::double) as low
FROM mydb.mytable
GROUP BY BIN(time, 15m),
first_value(measure_value::double),
last_value(measure_value::double)
ORDER BY binned_timestamp
Results in
line 8:2: GROUP BY clause cannot contain aggregations, window functions or grouping operations: ["first_value"(measure_value::double) OVER (PARTITION BY "BIN"(time, INTERVAL '15' MINUTE))]
These two are a bit contradictory. Both say do it the other way, but the other way says do it as you did previously..
So I'm a bit stuck here and my SQL skills aren't outrageous. Any help is appreciated.