---
source: https://iinventedlight.com/library/notes/sqlite-window-functions.md
title: "Use a SQLite window function or a Django Window expression"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Public-Domain (SQLite); BSD-3-Clause (Django docs); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: SQLite, Window Functions; Django docs, Query expressions. Public-Domain; BSD-3-Clause."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-19
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-19
as_of: 2026-11-19
confidence: medium
untested: "Not reproduced (2026-11-19). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: SQLite window functions and Django Window"
tags: [sqlite, window-functions, django, sql, orm]
client: Librarian
sources:
  - id: S1
    title: "Window Functions"
    publisher: SQLite
    url: https://www.sqlite.org/windowfunctions.html
    accessed: 2026-11-19
    license: "Public-Domain"
  - id: S2
    title: "Query expressions"
    publisher: Django docs
    url: https://docs.djangoproject.com/en/5.2/ref/models/expressions/
    accessed: 2026-11-19
    license: "BSD-3-Clause"
---
# Use a SQLite window function or a Django Window expression
**Answer:** A function with an `OVER` clause is a window function. Without that clause it is an ordinary aggregate or scalar function. The `Window` class is the main expression for an `OVER` clause.

## SQLite windows

Window functions come in two varieties: aggregate window functions and built-in window functions. All of SQLite's aggregate functions may be used as aggregate window functions. Unlike ordinary functions, window functions cannot use the `DISTINCT` keyword. The syntax can include `PARTITION BY` and a frame. `row_number()` is a built-in example. A `SELECT` can also contain named window-defs clauses.

## Django Window

Window functions provide a way to apply functions on partitions. Unlike a normal aggregation function, window functions operate on frames and partitions. They compute the result for each row. Multiple windows can appear in the same query. The ORM includes multiple expressions in a `annotate()` call. The template defaults to `%(expression)s OVER (%(window)s)`. `partition_by` and `order_by` are arguments on `Window`.

| OVER | Window |
|---|---|
| OVER clause | Marks a window function |
| PARTITION BY | partition_by on Window |
| built-in window functions | row_number() and similar |
| Window | Main expression for an OVER clause |

## See also

- [django-querysets](https://iinventedlight.com/library/notes/django-querysets/)
- [django-models](https://iinventedlight.com/library/notes/django-models/)
- [sqlite-query-planner-indexes](https://iinventedlight.com/library/notes/sqlite-query-planner-indexes/)

## Claims

- id: C1
  claim: A function with an OVER clause is a window function, not an ordinary aggregate.
  source: S1
  evidence: "If a function has an OVER clause, then it is a window function"

- id: C2
  claim: SQLite has aggregate window functions and built-in window functions.
  source: S1
  evidence: "aggregate window functions and built-in window functions"

- id: C3
  claim: Django's Window class is the main expression for an OVER clause.
  source: S2
  evidence: "The Window class is the main expression for an OVER clause"

## Sources

- [S1] Window Functions. SQLite. https://www.sqlite.org/windowfunctions.html . License: Public-Domain. Accessed 2026-11-19.

- [S2] Query expressions. Django docs. https://docs.djangoproject.com/en/5.2/ref/models/expressions/ . License: BSD-3-Clause. Accessed 2026-11-19.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: SQLite, Window Functions; Django docs, Query expressions. Public-Domain; BSD-3-Clause. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
