Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for not inserting primary keys into Sql Server tables #1343

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

miller45
Copy link

@miller45 miller45 commented Jun 1, 2023

Problem

Inserting values into IDENTITY columns on SQL Server (MS) will result in SQL Error:
insert explicit value for identity column in table 'tablename' when IDENTITY_INSERT is set to OFF
The are valid scenarios where you don´t want to (or cannot) alter the target tables of database just to "make kafka-connect happy".
But you might need to include the primary key in you kafka-connect config because you have to include it for the upsert mode/UPDATE case.
Related to #1287 and #837

Solution

Added option mssql.insert.primary.keys which defaults to true.
If set to false the INSERT will omit the primary key columns. This allows allows the database to create its own primary keys, if they are configured with IDENTITY(n,n) for autoincremental keys. This works for mode=insert and mode=upsert

Does this solution apply anywhere else?
  • yes
  • no
If yes, where?

Test Strategy

Testing done:
  • Unit tests
  • Integration tests
  • System tests
  • Manual tests

Release Plan

This feature is non-breaking by design. Given there is no bug, it will not change any existing behavior. So it can be released without any migration effort.

@miller45 miller45 requested a review from a team as a code owner June 1, 2023 14:56
@miller45 miller45 changed the title Option for not inserting primary keys into Sql Server tables and only… Option for not inserting primary keys into Sql Server tables Jun 1, 2023
@miller45 miller45 mentioned this pull request Jun 1, 2023
@cla-assistant
Copy link

cla-assistant bot commented Aug 1, 2023

CLA assistant check
All committers have signed the CLA.

@miller45
Copy link
Author

miller45 commented Aug 9, 2023

Problem

Inserting values into IDENTITY columns on SQL Server (MS) will result in SQL Error: insert explicit value for identity column in table 'tablename' when IDENTITY_INSERT is set to OFF There are valid scenarios where you don´t want to (or cannot) alter the target tables of database just to "make kafka-connect happy". But you might need to include the primary key in you kafka-connect config because you have to include it for the upsert mode/UPDATE case. Related to #1287 and #837

Solution

Added option mssql.insert.primary.keys which defaults to true. If set to false the INSERT will omit the primary key columns. This allows allows the database to create its own primary keys, if they are configured with IDENTITY(n,n) for autoincremental keys. This works for mode=insert and mode=upsert

Does this solution apply anywhere else?
  • yes
  • no
If yes, where?

Test Strategy

Testing done:
  • Unit tests
  • Integration tests
  • System tests
  • Manual tests

Release Plan

This feature is non-breaking by design. Given there is no bug, it will not change any existing behavior. So it can be released without any migration effort.

@AnthonyWhitaker
Copy link

@Tanish0019 Is it possible to get an ETA or other information on the likelihood of this getting merged? The changes look good to me and judging from StackOverflow and GitHub Issues - it would benefit a large number of people.

@Tanish0019
Copy link
Contributor

Hi @AnthonyWhitaker, yes looks like a valid issue. I will try to get to reviewing it soon.

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.

3 participants