Repository navigation
docs: a query over a foreign NaN float answers in PostgreSQL's order; CHECK constraints keep it out - #241
Merged
Conversation
…QL's order
The finite-only rule covers what the application creates, binds and loads;
a row another tool writes is answered in PostgreSQL's order by a query
that runs in the database, and only loading it throws. docs/efcore.md and
docs/why.md now say so, and recommend a CHECK constraint per column kind.
Measured on PostgreSQL 16 and 18: the bounds check (lower/upper NOT IN
NaN, Infinity, -Infinity) is complete for a range but not for a
multirange, whose lower and upper are its outer bounds -
{(,-Infinity],[1,2)} and {[1,2),[Infinity,)} pass it. The multirange
constraint checks its text instead; the array one uses &&.
FloatCheckConstraintTests reads the three expressions from the guide's
code block, applies them with HasCheckConstraint on float8 and float4
columns, and requires each non-finite literal refused and each finite,
unbounded, empty and NULL value stored. With the bounds check in place of
the multirange expression, 10 rows are stored and the test fails.
Closes #232
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #232
Problem
docs/why.mdanddocs/efcore.mdimplied the finite-only rule protects every query. It protects every value the application creates, binds and loads. Over a row another tool wrote, a query that runs in the database answers in PostgreSQL's order ([0,NaN)matchesContains(1e308)), and only loading the entity throws (#179, part B).Change
docs/efcore.md: a new Keep NaN and infinity out of a float column section. It states the boundary with the issue's three examples and gives oneHasCheckConstraintper column kind. The "Only finite values load" bullet links to it.docs/why.mdgets the same boundary in "Where is the model stricter than the database?". There are CHANGELOGDocs:lines (root and EF package).lower(x) NOT IN ('NaN','Infinity','-Infinity') AND upper(x) …) is complete for a range but not for a multirange. A multirange'slower/upperare its outer bounds, and they are NULL beside an unbounded side, which a CHECK lets pass. So{(,-Infinity],[1,2)},{(,-Infinity),[1,2)},{[1,2),[Infinity,)},{[1,2),(Infinity,)}and{(,0),[1,Infinity),[NaN,)}all pass it. The documented multirange constraint checks the text instead ("Bands"::text !~* '(nan|inf)'; a finite float never prints those letters). The array constraint isNOT ("Weights" && '{NaN,Infinity,-Infinity}').E60,E61andW06, held by the new test.Tests
FloatCheckConstraintTests(integration, PostgreSQL 17 in the suite; the same corpus ran by hand on 16 and 18):HasCheckConstrainton float8 and float4 range, multirange and array columns throughEnsureCreated. It requires every non-finite literal to fail with23514(22 per width, including the five multiranges above) and every finite, unbounded, empty and NULL value to be stored.Contains(1e308)over[0,NaN), a range containing a NaNdoublecolumn, andCountover{1,NaN}answer in PostgreSQL's order, and loading throwsArgumentException.🤖 Generated with Claude Code