I have a following query:
WITH t as (
SELECT date_trunc(\'hour\', time_series) as trunc
FROM generate_series(\'2013-02-27 22:00\'::timestamp, \'2013-02-
Try:
WITH t as (
SELECT time_series as trunc
FROM generate_series('2013-02-27 22:00'::timestamp, '2013-02-28 2:00',
'1 hour') as time_series
)
SELECT DISTINCT ON(t.trunc) t.trunc, e.id
FROM t
JOIN event e
ON e.created < t.trunc
ORDER BY t.trunc, e.created DESC
If it is too slow - tell me. I will give you a faster query.