Issue with upsert based on database generated Identity
See original GitHub issueAs i am trying to use the Upsert with PostgreSql. I am getting the exception as I am doing upsert over database generated Identity. This exception is being introduces in v2.0.1 with comments :
Explicitly throwing an exception when using identity keys as upsert match columns (since it wouldn’t have worked correctly anyway)
In my use case i am not allowed to go away with database generated option hence i tried to run it with commenting with this code :
//if (joinColumns.All(p => p.ValueGenerated != ValueGenerated.Never))
// throw new InvalidMatchColumnsException();
And this worked 😃
Hence i am exploring the option where we can allow user to flag this condition out and has the flexibility of allowing the database generated option
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
PostgreSQL - on conflict update for GENERATED ALWAYS ...
1 Answer. You shouldn't be too worried about the data churn – after all, an UPDATE also writes a new version of the...
Read more >Upsert fails and not respecting auto increment on primary key
As I understand your issue, you are trying to perform Upsert in SQL table which is having PersonID as identity column . However,...
Read more >3070791 - INSERT, UPDATE and UPSERT are disallowed ...
The tables were generated using Java EclipseLink JPA provider package, when attempting to import data, it result in the Identity column error. This...
Read more >Postgres: with identity column as unique key, need help in ...
Detail: Column "id" is an identity column defined as GENERATED ALWAYS. First question: Why am I getting insert error while the select query ......
Read more >What is an upsert, and when should you use one?
In the context of relational databases, an upsert is a database ... If the employee ID exists in the table, update that row...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So I might not agree with upserting on identity keys (there are much better ways to do that if all you want to do is update an existing entry by PK), but I will agree that it’s not a bad idea to add that as an option… There might be cases when it would actually make sense anyway (
IDENTITY_INSERT
in MSSQL).I’ve got basic support for it added just now, and it should go live with the next release.
To enable it, just call
.AllowIdentityMatch()
on theUpsertCommandBuilder
Thanks for adding in this feature. as @jlucaspains mentions it’s very useful for disconnected entities.