I'm trying to get a cumulative count of distinct objects in Redshift over a time series. The straightforward thing would be to use COUNT(DISTINCT myfield) OVER (ORDER BY timefield DESC ROWS UNBOUNDED PRECEDING)
, but Redshift gives a "Window definition is not supported" error.
For example, the code below is trying to find the cumulative distinct users for every week from the first week to the present. However, I get the "Window function not supported" error.
SELECT user_time.weeks_ago,
COUNT(distinct user_time.user_id) OVER
(ORDER BY weeks_ago desc ROWS UNBOUNDED PRECEDING) as count
FROM (SELECT FLOOR(EXTRACT(DAY FROM sysdate - ev.time) / 7) AS weeks_ago,
ev.user_id as user_id
FROM events as ev
WHERE ev.action='some_user_action') as user_time
The goal is to build a cumulative time series of unique users who have performed an action. Any ideas on how to do this?