Skip to content

Instantly share code, notes, and snippets.

@Pomeha
Created March 1, 2021 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pomeha/935db63087343165a5e132beb51a3171 to your computer and use it in GitHub Desktop.
Save Pomeha/935db63087343165a5e132beb51a3171 to your computer and use it in GitHub Desktop.
Limit by record type on table
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment