Diagnostic Queries
Symptoms
A window function was called without the required OVER clause. Window functions must specify a window, so PostgreSQL raises SQLSTATE 42P20 (windowing_error).
- A function like
rank()orrow_number()used without OVER. - These functions are not aggregates and need a window definition.
- Common when confusing window functions with aggregates.
What the server log shows
ERROR: window function rank requires an OVER clause
Why PostgreSQL raises this — what the manual says
Section 3.5 Window Functions:
“A window function call always contains an OVER clause directly following the window function’s name and argument(s).”
Window functions operate over a set of rows defined by OVER (partitioning/ordering). Without it, the function has no window to compute over, so PostgreSQL rejects the call with 42P20.
Common causes
- Calling a window-only function without
OVER. - Treating
row_number()/rank()like a scalar function. - Forgetting the window definition.
How to fix it
- Add an OVER clause:
rank() OVER (ORDER BY score DESC). - Use
OVER ()for a single full-result window if appropriate. - If you meant an aggregate, use the aggregate function with GROUP BY instead.
Related & next steps
Reference: PostgreSQL 18 Section 3.5 “Window Functions”.
Thanks — noted. This helps keep the database accurate.