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

Bulk insert not possible for tables that contain timestamp columns #255

Closed
peterdouce opened this issue Jul 6, 2022 · 3 comments
Closed

Comments

@peterdouce
Copy link

When a table contains a timestamp (rowversion) column (for optimistic concurrency) it's currently impossible to do a bulk insert as it tries to insert a value in a column that can't be assigned. This is a similar issue as with the "generated always / hidden" columns in #99

Expected behaviour:

Timestamp columns shouldn't be included in the generated insert statement or should get DEFAULT as value. See error output.

Actual behaviour:

bulk insert fails with the following error

RequestError: Cannot insert an explicit value into a timestamp column. Use INSERT with a column list to exclude the timestamp column, or insert a DEFAULT into the timestamp column.
    at done (.\node_modules\mssql\lib\msnodesqlv8\request.js:192:21)
    at .\node_modules\msnodesqlv8\lib\table.js:1085:25
    at runNextTicks (node:internal/process/task_queues:61:5)
    at processImmediate (node:internal/timers:437:9) {
  code: 'EREQUEST',
  originalError: [Error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot insert an explicit value into a timestamp column. Use INSERT with a column list to exclude the timestamp column, or insert a DEFAULT into the timestamp column.] {
    sqlstate: '23000',
    code: 273,
    severity: 16,
    serverName: 'FSM075652',
    procName: '',
    lineNumber: 1
  },
  number: 273,
  lineNumber: 1,
  state: '23000',
  class: 16,
  serverName: 'FSM075652',
  procName: ''
}

Software versions

  • NodeJS: 16.14
  • node-sqlserver-v8: 2.4.8 (issue is also in 2.5.0)
  • SQL Server: 2016

Possible fix

When I add "|| col.type === 'timestamp'" in table.js it works but there may be a better solution?

readOnly (col) {
    return (col.is_identity || col.is_computed || col.is_hidden || col.generated_always_type || col.type === 'timestamp')
}
@TimelordUK
Copy link
Owner

TimelordUK commented Jul 6, 2022 via email

@TimelordUK
Copy link
Owner

your fix is fine - it is currently on master but will be a couple weeks before release as am testing MS v18 driver and have some other fixes to look at

@peterdouce
Copy link
Author

ok thanks for the update

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

No branches or pull requests

2 participants