Skip to content

Bulk insert not possible for tables, that contain columns with GENERATED ALWAYS (i.e. Temporal Tables) #99

@olsn

Description

@olsn

I've started of trying this via node-mssql, but could track down the issue to this library. (Original issue-report linked here: tediousjs/node-mssql#880)


The issue is, that the TableMgr genereates the Insert-Signatures and includes the system-columns, even if they are set to GENERATED ALWAYS or HIDDEN (as is the case for the time-columns in temporal tables)

The following is the error-message:

[Error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot insert an explicit value into a GENERATED ALWAYS column in table 'TEST.dbo.MyTemporalTestTable'. Use INSERT with a column list to exclude the GENERATED ALWAYS column, or insert a DEFAULT into GENERATED ALWAYS column.] {
  sqlstate: '42000',
  code: 13536
}

I've got this to work which adjusting the recalculateAssignableColumns in table.js:68 (https://github.com/TimelordUK/node-sqlserver-v8/blob/master/lib/table.js#L68)
With the following code:

    function Meta (tableName, cols) {
	  cols = cols.filter(col =>  col.name !== "ValidFrom" && col.name !== "ValidTo");
		
      function getFullName () {
      ...

However this is not a proper fix, as the names of the system-time-columns are arbitrary and the user can set any name. (in my case I chose ValidFrom and ValidTo.
I've looked into the description-meta-data of the table as well, but I don't see any usable information about the columns, that are being generated - is_compute is false for those columns.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions