Skip to content

Instantly share code, notes, and snippets.

@barsbek
Created March 19, 2018 17:17
Show Gist options
  • Save barsbek/2a498941f9fd7c5de082a2c210bd40ac to your computer and use it in GitHub Desktop.
Save barsbek/2a498941f9fd7c5de082a2c210bd40ac to your computer and use it in GitHub Desktop.
postgresql: set frame's range in window function
select count(*) over(order by id rows between unbounded preceding and unbounded following); -- all rows in partition
select count(*) over(order by id rows between 2 preceding and 1 following); -- 2 rows before, current and next row
select count(*) over(order by id rows unbounded preceding); -- all rows before current
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment