8000 fix(postgres): type a window aggregate over the current row as not null by colinhacks · Pull Request #113 · colinhacks/reylo · GitHub
[go: up one dir, main page]

Skip to content

fix(postgres): type a window aggregate over the current row as not null - #113

Merged
colinhacks merged 2 commits into
mainfrom
window-nonnull
Oct 24, 2026
Merged

colinhacks merged 2 commits into
mainfrom
window-nonnull

Conversation

@colinhacks
Copy link
Copy Markdown
Owner

An aggregate used as a window function was typed nullable whatever its frame. Such an aggregate (sum, avg, min, max, bit_and, bit_or, bool_and, bool_or, every, string_agg, array_agg and the JSON aggregates) is NULL only when no non-null input reaches it, and a frame that always holds the current row has that row's input. So now, as under a plain GROUP BY, it follows its argument there: non-null when the argument is (array_agg and the JSON aggregates are non-null outright).

Column Before After
sum(count(*)) over (order by date_trunc('month', published_at)), grouped by the month nullable non-null
sum(p.id) over (order by p.id), over (), over (partition by p.user_id) nullable non-null
max(p.title) over (partition by p.user_id) nullable non-null
sum(p.id) over w with window w as (partition by p.user_id order by p.id) nullable non-null
sum(p.id) over (order by p.id rows between 1 following and 2 following) nullable nullable
sum(p.id) filter (where …) over () nullable nullable
sum(p.id) with no group by nullable nullable

Frames that hold the current row. No frame clause (RANGE UNBOUNDED PRECEDING, through the current row's last peer, or the whole partition without ORDER BY), and any ROWS, RANGE or GROUPS frame that starts at UNBOUNDED PRECEDING, n PRECEDING or CURRENT ROW and ends at CURRENT ROW, n FOLLOWING or UNBOUNDED FOLLOWING, with EXCLUDE TIES or EXCLUDE NO OTHERS. An offset must be non-null and non-negative or the statement fails, and in RANGE mode the current row is no distance from itself, NULL, NaN and the infinities included (measured on PostgreSQL 18 over float8, numeric and timestamptz, and checked by the oracle's edge values).

Frames that can leave it out, which stay nullable: a start n FOLLOWING, an end n PRECEDING, EXCLUDE CURRENT ROW and EXCLUDE GROUP, and any aggregate with a FILTER.

Named windows. OVER w takes the frame of w in the statement's WINDOW clause (nothing is claimed when no such window is there); OVER (w …) and AS (w …) use their own frame clause, since the server refuses to copy a window that has one.

The rule is frame_holds_current_row in engine/postgres/src/infer.rs, read from the parser's frame option bits, and jsonshape.rs uses it too, so a JSON aggregate over such a window is a non-null JSON array.

  • New oracle case oracle/cases/window_aggregates: 20 statements over every frame above, with NULL, NaN and infinite ordering values. No other case's expected.txt changed.
  • The Postgres page's window functions entry states the rule, and its example gains a running total, captured again.
  • MySQL and SQLite have the same gap; their engines are separate and are left to their own pull requests.

Checks: cargo build --workspace --all-targets with no warning, cargo test of every crate, the whole oracle with --strict-coverage (131 cases, 0 failed), engine/build.sh (only the Postgres artifact changes), nub run typecheck, nub run test with both databases (254 passed, 0 skipped), nub run build, and the site's capture and build.

Copilot AI balanced review requested due to automatic review settings October 24, 2026 02:22
@pullfrog
pullfrog Bot commented Oct 24, 2026 •
Copy link
Copy Markdown
Contributor

No configured credential can serve this run. Your Claude Pro/Max subscription has hit its usage limit, which resets at 2026-10-26 08:00 UTC. Re-trigger after it resets, or add an API key for this provider, which Pullfrog falls back to automatically.

The providers' responses
CLAUDE_CODE_OAUTH_TOKEN: 429: This request would exceed your account's rate limit. Please try again later.

Pick another model →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using claude-opus-5-5

@vercel
vercel Bot commented Oct 24, 2026 •
Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
reylo Ready Ready Preview Oct 24, 2026 2:23am UTC

Request Review

Copilot AI left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@colinhacks
colinhacks merged commit 51183f3 into main Oct 24, 2026
6 of 7 checks passed
@colinhacks
colinhacks deleted the window-nonnull branch October 24, 2026 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0