Skip to content

[Draft] Add experimental ExecuteMerge / upsert support for PostgreSQL - #4108

Draft
SkyDevLab wants to merge 2 commits into
npgsql:mainfrom
SkyDevLab:feature/execute-merge-upsert
Draft

SkyDevLab wants to merge 2 commits into
npgsql:mainfrom
SkyDevLab:feature/execute-merge-upsert

Conversation

@SkyDevLab

Copy link
Copy Markdown

Description

This draft PR implements PostgreSQL provider support for the experimental ExecuteMerge / upsert feature tracking dotnet/efcore#4526 and complementing the experimental SQLite implementation in dotnet/efcore#39100.

Key Additions

  • NpgsqlQuerySqlGenerator:
    • Handles MergeColumnReferenceExpression to emit EXCLUDED."column" for incoming values and delimited identifiers for existing values.
    • Implements VisitMerge(MergeExpression) lowering to INSERT ... ON CONFLICT (...) DO UPDATE / DO NOTHING with optional RETURNING clause.
    • Emits WHERE FALSE (instead of SQLite's WHERE 0) for empty source row collections to comply with PostgreSQL's strict boolean requirement.
  • NpgsqlQueryableMethodTranslatingExpressionVisitor:
    • Overrides TranslateExecuteMerge to validate table RETURNING clause settings and guard against unsupported engines (Amazon Redshift).
  • Specification Tests:
    • Adds ExecuteMergeNpgsqlFixture and ExecuteMergeNpgsqlTest inheriting from ExecuteMergeRelationalTestBase.

Note: This PR is opened as a draft pending review and merge of upstream dotnet/efcore#39100 and its availability in daily build feeds.

@omri-klein-semperis

Copy link
Copy Markdown

Hey @SkyDevLab, are you still working on this? dotnet/efcore#39100 is merged now, so this can be built against main.
If you don't have time for it, no worries, just let me know and I'll pick it up. If I don't hear back in a week or so, I'll take it over.

@SkyDevLab

Copy link
Copy Markdown
Author

Hey @omri-klein-semperis, yes, definitely still on it! Congrats on getting dotnet/efcore#39100 merged!

Now that the core abstractions have landed in EF Core main, I'm rebasing this against upstream and aligning with the latest merged changes. I'll push an updated commit shortly.

@SkyDevLab
SkyDevLab force-pushed the feature/execute-merge-upsert branch from 82d243d to 38e9f41 Compare November 16, 2026 16:48
@SkyDevLab
SkyDevLab force-pushed the feature/execute-merge-upsert branch from 38e9f41 to 485e1e7 Compare November 27, 2026 16:51
@SkyDevLab

Copy link
Copy Markdown
Author

@omri-klein-semperis Rebased feature/execute-merge-upsert onto the latest main (c92dc5ce).

Note that dotnet/efcore#39100 landed in EF Core 12.0-preview1, whereas npgsql/efcore.pg main currently still references <EFCoreVersion>11.0.0</EFCoreVersion> ([11.0.0,12.0.0)), so MergeExpression, MergeColumnReferenceExpression, and ExecuteMergeMatch are not yet present in the referenced EF Core packages. Once efcore.pg syncs to EF Core 12.0-preview1 packages, this PR will be ready to build and mark ready for review.

This branch has not been deployed

No deployments
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