I have a table like this,
event_id | date ----------+------------------------ 1703702 | 2013-06-25 07:50:57-04 3197588 | 2013-06-25
WITH diffs as ( SELECT event_id, date - lag(date) over (partition BY event_id ORDER BY date) as difference FROM TABLE ) SELECT event_id, array_agg( difference ) as all_diffs FROM diffs GROUP BY event_id;
Should work.