pull down to refresh

For the longest time all of our stats for display have been done via materialized views. This is convenient but grew aggravating as changing and iterating on their design is expensive; they're relatively inflexible. The move afaict is to create real tables that can be updated incrementally and in an idempotent way.
TIL about GROUPING SETS in postgres and the ability to create bitmasks with GROUPING which are really helpful because we want seven groups afaict (bucket is a time bucket):
    GROUP BY GROUPING SETS (
        (bucket),                                -- 7  GLOBAL
        (bucket, "payInType"),                   -- 6  GLOBAL_BY_TYPE
        (bucket, "subName"),                     -- 5  SUB_TOTAL         (kept even if subName is NULL)
        (bucket, "subName","payInType"),         -- 4  SUB_BY_TYPE       (kept even if subName is NULL)
        (bucket, "userId"),                      -- 3  USER_TOTAL
        (bucket, "userId","payInType"),          -- 2  USER_BY_TYPE
        (bucket, "subName","userId"),            -- 1  SUB_BY_USER       (kept even if subName is NULL)
        (bucket, "userId","subName","payInType") -- 0  USER_SUB_BY_TYPE  (kept even if subName is NULL)
    ))