Skip to content

docs: ordering by a bound puts the rows without it where PostgreSQL puts NULLs - #372

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
docs/359-bound-ordering
Oct 24, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
docs/359-bound-ordering

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #359

Problem

docs/ranges.md#sort-ranges documents a deliberate difference: PostgreSQL puts NULL last in an ascending ORDER BY, and memory puts null first. It says that for a nullable column only. An ordering by LowerBound() or UpperBound() meets the same difference on any column, because the bound of an empty or unbounded range is NULL. A grid sorted by "from" therefore shows open-start and empty rows at the bottom when it sorts in the database, and at the top when it sorts in memory. Four examples show exactly that ordering with no word about it: the README, the EF Core package README, docs/efcore.md and docs/getting-started.md, where the result is called chronological.

Change

Docs only. The behaviour follows the documented decision; no translation changes.

  • docs/efcore.md#read-bounds-merge-ranges-and-aggregate: a "Good to know" bullet. It gives the placement: the empty rows and the rows without that bound sort last ascending and first descending, also on a required column. It also gives two ways to sort otherwise: a != null key in front (OrderBy(b => b.Period.LowerBound() != null).ThenBy(b => b.Period.LowerBound())) gives memory's order, and OrderBy(b => b.Period) gives the range order, where open starts come first. Claim E72 quotes it.
  • docs/ranges.md#sort-ranges: the NULL bullet says the same holds for an ordering by a bound, and links there.
  • The four examples: a comment says where the rows with no start go.
  • Changelogs (root, EF Core): a Docs: line under ### Fixed in [11.0.0-preview.1]. The EF Core changelog gets that section here. The 10.x side is 10.x: docs: ordering by LowerBound() or UpperBound() puts open-ended and empty rows where PostgreSQL puts NULLs (port of #359) #364.

Tests

  • ExecutedQueryTests.OrderingByABound_PutsTheRowsWithoutItWherePostgresPutsNulls (new, ids 2700–2708) orders a range column and a multirange column holding every shape by each bound, in both directions. It asserts the documented placement: memory's order with the null-bound rows moved to the end ascending and the front descending. It also asserts that the Bound() != null key gives memory's order exactly.
  • Seed bound-declared-null-only-for-a-null-argument.patch (LowerBound() and UpperBound() in a query: == null becomes WHERE FALSE and ?? max loses its COALESCE, because lower() and upper() are declared NULL only for a NULL argument #349 reverted, which no seed held yet): dotnet run tools/oracles.cs seeds bound-declared reports it caught by ExecutedQueryTests, 2 of 17 failing. Applied by hand, the new test fails on the keyed order, because LowerBound() != null folds to TRUE and the order falls back to the database's.
  • Full suite on postgres:16-alpine: all eight projects pass (core 1399, NodaTime 239, EF 297, EF NodaTime 83, ASP.NET Core 92, conventions 409, integration 289, infinity-disabled 4).

🤖 Generated with Claude Code

…uts NULLs (#359)

docs/ranges.md#sort-ranges documents PostgreSQL's NULLS LAST against memory's
null-first for a nullable column, but not for an ordering by a bound, where the
NULLs come from non-null ranges and so appear on a required column too, and the
README, the EF Core README, docs/efcore.md and getting-started.md all show
OrderBy(b => b.Period.LowerBound()) as their ordering example.

docs/efcore.md gets a Good to know bullet with the placement (last ascending,
first descending) and the two ways to sort otherwise: a Bound() != null key in
front gives memory's order, ordering by the range gives the range order. The
ranges.md bullet and the four examples point there. Claim E72.

ExecutedQueryTests.OrderingByABound_PutsTheRowsWithoutItWherePostgresPutsNulls
orders a range and a multirange column of every shape by each bound in both
directions and asserts the documented placement and the keyed order. The seed
bound-declared-null-only-for-a-null-argument.patch (#349 reverted) is caught by
it and by the bound sweep.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Oct 24, 2026
@CaffeinatedCoder CaffeinatedCoder added documentation Improvements or additions to documentation area/ranges Range unions, variants and the shape engines area/range-set RangeSet and multirange algebra package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/efcore-nodatime Affects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime labels Oct 24, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 818e61b into main Oct 24, 2026
11 of 13 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the docs/359-bound-ordering branch October 24, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/range-set RangeSet and multirange algebra area/ranges Range unions, variants and the shape engines documentation Improvements or additions to documentation package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/efcore-nodatime Affects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs: ordering by LowerBound() or UpperBound() puts open-ended and empty rows where PostgreSQL puts NULLs, also on a required column

1 participant