This is the query I have so far, to create daily bars:
SELECT DISTINCT date_trunc('hour',t) AS date,
min(price) OVER w,
max(price) OVER w,
first_value(price) OVER w,
last_value(price) OVER w
FROM ticker
WINDOW w AS (PARTITION BY date_trunc('hour',t));
Changing 'hour' to 'min' or 'day' would give me the bars corresponding to these units.
However, what if I want 5 min or 15 min bars? date_trunc()
doesn't support these and I'm looking for a nice elegant way to do it.