SQLSTATE 42P20 ERROR Class 42: Syntax Error or Access Rule Violation

windowing_error window function … requires an OVER clause — 42P20

PostgreSQL error "window function … requires an OVER clause" (SQLSTATE 42P20): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

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() or row_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

  1. Add an OVER clause: rank() OVER (ORDER BY score DESC).
  2. Use OVER () for a single full-result window if appropriate.
  3. If you meant an aggregate, use the aggregate function with GROUP BY instead.

Related & next steps

Reference: PostgreSQL 18 Section 3.5 “Window Functions”.

Was this helpful?