How to fold an event stream into a table?
assuming the are no duplicate events you can do this.

create view "users" as
  select payload-&gt;&gt;'name'
  from es.events
  group by 1
  having
      sum ( case type 
            when 'user-registered' then 1
            when 'user-banned' then -1 
            end ) &gt; 0
union 
  select payload-&gt;&gt;'activation_token'
  from es.events
  where type='user-changed-password';