Skip to content

docs: PostgreSQL 18 temporal keys over a range column (10.x) - #193

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
docs/temporal-keys
Oct 18, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
docs/temporal-keys

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #97

Problem

PostgreSQL 18's temporal keys, UNIQUE (… WITHOUT OVERLAPS) and FOREIGN KEY (… PERIOD …), were undocumented. They are the built-in form of the exclusion-constraint recipe, and the foreign key adds referential integrity across time, which an exclusion constraint cannot give. On the 10.x line (Npgsql 10), EFCore.ComplexIndexes.PostgreSQL declares both. Two postgres-surface.json rows were open under this issue. The exclusion-constraint box also gave only migrations and raw SQL as ways to get the constraint, while UseNpgsqlComplexIndexes() makes EnsureCreated() create it as well (#97's last comment).

Change

  • docs/efcore.md#reject-overlapping-rows-with-a-temporal-key-postgresql-18 (new, next to the exclusion constraint) covers HasTemporalConstraint and the constraint text PostgreSQL reads back, plus the 23P01 failure shape and which rows are still saved. It then covers HasTemporalForeignKey and its FOREIGN KEY … PERIOD text: coverage across adjacent principal rows, 23503 for an uncovered period or unknown key, and why the principal needs a temporal key. Good to know: PostgreSQL 18 only, btree_gist created for you, EnsureCreated() needs UseNpgsqlComplexIndexes(), and the API is ComplexIndexes' (this package adds none, as the issue says).
  • Exclusion-constraint box: it names UseNpgsqlComplexIndexes() as the third way. The sentences E42 quotes are unchanged.
  • docs/getting-started.md now says the constraint can be a temporal key on 18.
  • Catalogues: claims E48–E53, all held by ComplexIndexesCrossTests. The PRIMARY KEY … WITHOUT OVERLAPS and FOREIGN KEY … PERIOD surface rows are waived to the new section, as the exclusion-constraint row is. The waivers name Npgsql 11's HasWithoutOverlaps/HasPeriod (Native temporal keys over ValueRanges columns on the 11 line: implement INpgsqlRangeTypeMapping, document WithoutOverlaps and WithPeriod #150) as the native form on the 11.x line.
  • Changelogs: a Docs: line under 10.0.0 ### Added in the root and EF Core changelogs.

Tests

Every statement in the section is measured in ComplexIndexesCrossTests (PostgreSQL 18.x alpine, ComplexIndexes 5.4.0). The measurements already in place from #159 cover the temporal key over DateRange, RangeSet<DateRange, DateOnly> and TimeRange: the rendered and read-back UNIQUE text, 23P01 with ConstraintName, adjacent rows and other keys saved, and nothing created without the runtime differ. This PR adds:

  • TemporalForeignKey_AcceptsACoveredPeriod_AndRejectsOneThatIsNot. It checks the rendered and read-back FOREIGN KEY ("RoomId", PERIOD "Period") REFERENCES "Availabilities"("RoomId", PERIOD "Period") and that btree_gist was created. A booking covered only by two adjacent availabilities together is saved. One past them, or for a room with no availability, fails as 23503 naming the constraint. Without UseNpgsqlComplexIndexes() the test fails (checked).
  • TemporalConstraint_IsASyntaxError_BeforePostgres18 checks that the same schema on PostgreSQL 16 throws 42601.
  • The UNIQUE test now also asserts that btree_gist exists.

Conventions (catalogue, surface, changelog) and the full integration suite (233) pass locally.

🤖 Generated with Claude Code

A docs/efcore.md section next to the exclusion constraint: UNIQUE (… WITHOUT OVERLAPS) through
EFCore.ComplexIndexes.PostgreSQL's HasTemporalConstraint, and FOREIGN KEY (… PERIOD …) through
its HasTemporalForeignKey, over this package's range and multirange columns. The exclusion
constraint box names UseNpgsqlComplexIndexes() as the third way to get the constraints from
EnsureCreated().

Every sentence is measured in ComplexIndexesCrossTests, which gains the temporal foreign key
(covered across two adjacent principal rows is saved, past them or for an unknown key is 23503),
the btree_gist extension check, and the syntax error on PostgreSQL 16. Claims E48–E53; the two
postgres-surface rows are waived to the section, with Npgsql 11's native API on the 11.x line
(#150) named as the other form.

Closes #97

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 10.0.0 milestone Oct 18, 2026
@CaffeinatedCoder CaffeinatedCoder added documentation Improvements or additions to documentation area/ranges Range unions, variants and the shape engines package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL labels Oct 18, 2026
# Conflicts:
#	CHANGELOG.md
#	src/CodoMetis.ValueRanges.EFCore.PostgreSQL/CHANGELOG.md
#	test/oracles/claims.json
@CaffeinatedCoder
CaffeinatedCoder merged commit 0fa745e into main Oct 18, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the docs/temporal-keys branch October 18, 2026 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ranges Range unions, variants and the shape engines documentation Improvements or additions to documentation package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document PostgreSQL 18 temporal keys over a range column: PRIMARY KEY … WITHOUT OVERLAPS and FOREIGN KEY … PERIOD

1 participant