Bird
0
0

Why does RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW include all rows with the same ordering value as the current row, but ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW does not?

hard📝 Conceptual Q10 of 15
PostgreSQL - Window Functions in PostgreSQL
Why does RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW include all rows with the same ordering value as the current row, but ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW does not?
ABecause ROWS frames ignore the ORDER BY clause.
BBecause RANGE frames only include the current row.
CBecause RANGE frames are based on value ranges, including peers, while ROWS frames are based on physical row positions.
DBecause ROWS frames include all rows with the same value.
Step-by-Step Solution
Solution:
  1. Step 1: Understand RANGE behavior

    RANGE frames include all rows with ordering values within the specified range, including peers.
  2. Step 2: Understand ROWS behavior

    ROWS frames count physical rows relative to current row, ignoring value equality.
  3. Final Answer:

    Because RANGE frames are based on value ranges, including peers, while ROWS frames are based on physical row positions. -> Option C
  4. Quick Check:

    RANGE = value range; ROWS = physical rows [OK]
Quick Trick: RANGE includes peers by value; ROWS counts rows physically [OK]
Common Mistakes:
  • Thinking ROWS ignores ORDER BY
  • Assuming RANGE excludes peers
  • Confusing frame definitions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes