← All notes

PostgreSQL window functions

Short answer

A window function computes across related rows while still returning one result per input row. You always write an OVER clause. [S1][S2]

Sketch

SELECT dept, name, salary,
       rank() OVER (PARTITION BY dept ORDER BY salary DESC)
FROM employees;

Points

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).

Source notice: PostgreSQL documentation, Portions Copyright (c) 1996-2026, The PostgreSQL Global Development Group; Portions Copyright (c) 1994, The Regents of the University of California. Used under the PostgreSQL License (https://www.postgresql.org/about/licence/).

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: PostgreSQL Global Development Group, PostgreSQL docs 3.5: Window Functions, PostgreSQL License; PostgreSQL Global Development Group, Window Functions, PostgreSQL License.

Cite this

Permanent ID: iil:note:m9s2dh61

iinventedlight. 2026. "PostgreSQL window functions: OVER, PARTITION BY, ORDER BY." iinventedlight Library, iil:note:m9s2dh61, version of 2026-11-04. https://iinventedlight.com/library/notes/postgres-window-functions/. License: CC-BY-4.0.

@misc{iil_note_m9s2dh61,
  author = {{iinventedlight}},
  title = {{PostgreSQL window functions: OVER, PARTITION BY, ORDER BY}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-04},
  url = {https://iinventedlight.com/library/notes/postgres-window-functions/},
  note = {Permanent ID iil:note:m9s2dh61. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/postgres-window-functions.md.