question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with upsert based on database generated Identity

See original GitHub issue

As 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:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
artiomchicommented, Oct 12, 2019

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 the UpsertCommandBuilder

1reaction
Kronos11commented, Jun 1, 2020

Thanks for adding in this feature. as @jlucaspains mentions it’s very useful for disconnected entities.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found