Repository navigation
fix(postgresql): coalesce a nullable operand of a typed concatenation - #123
Merged
Merged
Conversation
This was referenced Oct 20, 2026
…#94) C# concatenates null as an empty string; PostgreSQL's || returns NULL. x => x.Code + x.Suffix on a string? Suffix rendered ("Code" || "Suffix"), NULL for every row without a suffix: the index served no EF Core query over the lambda (EF Core writes COALESCE("Suffix", '')), and a unique index checked none of those rows. Silent: it scaffolded and applied. An operand that can be null is wrapped in coalesce(…, ''), a non-string one cast to text first, and a captured null is ''. A concatenation is therefore never null, so a filter comparing one needs no null check. The template is stored at the declaration, so a snapshot written before holds the old template and the next migrations add re-creates the index once. No rendering version is involved; 5.5.0 stays at 3. Verified with the translator change reverted: the parity sweep fails 71 rows (this change removes them from waivers.txt), and the new tests fail, including a live unique index that admitted two rows with code A and no suffix. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CaffeinatedCoder
force-pushed
the
fix/80-char-hasvalue-scalar-members
branch
from
October 20, 2026 06:35
472139d to
cfa3ed0
Compare
CaffeinatedCoder
force-pushed
the
fix/94-concat-coalesce
branch
from
October 20, 2026 06:35
2b57fc3 to
a7e3927
Compare
CaffeinatedCoder
changed the base branch from
fix/80-char-hasvalue-scalar-members
to
main
October 20, 2026 07:01
# Conflicts: # CHANGELOG.md
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 #94
Stacked on #122 (#80), which is stacked on #121 (the parity sweep); merge those first.
Problem
C# concatenates null as an empty string; PostgreSQL's
||returns NULL. A typed expression index or filter overx => x.Code + x.Suffixwithstring? Suffixscaffolded("Code" || "Suffix"), where EF Core's query for the same lambda writes"Code" || COALESCE("Suffix", ''). The index held NULL for every row without a suffix, so it served no EF Core query over the lambda, and a unique one checked none of those rows: two rows with codeAand no suffix both went in. It scaffolded and applied cleanly.Change
NpgsqlLinqIndexTranslator: each operand of a string concatenation that can be null is wrapped incoalesce(…, '')(a non-string one cast to text first, asCOALESCEneeds one type), a captured null becomes'', and a concatenation is never null, so a filter that compares one adds no null check. Operands that cannot be null render as before.migrations adddrops and re-creates the index once (Nullable_concatenation_recreates_once).waivers.txt: the Typed expression indexes: string concatenation with a nullable operand differs from EF Core (COALESCE) #94 block is gone. Its last 20 rows concatenate a non-string column (x.NStr + x.Int), which now matches EF Core except for EF Core's::text, so they join the existing block for that.### Changed answersrow (root and PostgreSQL) and the intro now counts six;docs/upgrading.md: "Concatenation with a nullable operand" under Changed answers in 5.5.0;docs/postgresql-indexes.mdnames the rule.Tests
NpgsqlLinqExpressionIndexTests: nullable operands are coalesced and non-nullable ones are unchanged; an index declared with the old template re-creates once and is then stable.PostgresIntegrationTests.Typed_concatenation_coalesces_a_nullable_operand: a unique index onCode + Suffixrefuses a second row with codeAand no suffix.🤖 Generated with Claude Code