SELECT * FROM 
(
  SELECT (CASE WHEN post_id IS NOT NULL THEN ROW_NUMBER() OVER (PARTITION BY (post_id IS NOT NULL)::integer) END) AS r_post,
         (CASE WHEN event_id IS NOT NULL THEN ROW_NUMBER() OVER (PARTITION BY (event_id IS NOT NULL)::integer) END) AS r_event,
         t.*
  FROM feed_items t)
feed_items
WHERE r_post <= VALUE OR r_event <= VALUE;
