Skip to content

Bulk insert to table that contains GENERATED ALWAYS Columns does not seem to work #880

@olsn

Description

@olsn

Up front: I'm using https://github.com/TimelordUK/node-sqlserver-v8 - so I'm not 100% sure if the issue is correct here or should be posten in https://github.com/TimelordUK/node-sqlserver-v8

Bulk insert to table that contains GENERATED ALWAYS Columns (temporal table) does not seem to work? (Or i'm using it wrong)

The following is the table:

CREATE TABLE dbo.MyTable {
 "Id"  varchar(255) NOT NULL, 
 "ValidFrom" datetime2 GENERATED ALWAYS AS ROW START HIDDEN NOT NULL,
 "ValidTo" datetime2 GENERATED ALWAYS AS ROW END HIDDEN NOT NULL,
 PERIOD FOR SYSTEM_TIME (ValidFrom, ValidTo),
 PRIMARY KEY ("Id")
)
WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [dbo].[MyTableHistory]))

(i've also tried to make the columns not HIDDEN and also NULLable but that did not change the bulk-insert behavior.

And i'm doing a simple bulk insert:

const table = new sql.Table("MyTable")
table.columns.add('Id', sql.VarChar(255), {nullable: false, primary: true})
// I've also tried to add the versioning-columns(ValidFrom and ValidTo) here and tried out different default-values, but no luck yet
table.rows.add("foo1");
table.rows.add("foo2");
table.rows.add("foo3");

const request = new sql.Request();
await request.bulk(table);

Expected behaviour:

Bulk-insert should work without error. (I'm very sure it's not the DB, because it works fine in a small Java-Test via JDBC)

Inserting via plain SQL INSERT-Statement works fine as well (but I have to insert a couple thousand rows, which seemed to bit a bit slow via a genereated plain INSERT statement (even with insertin 1000 at once))

Actual behaviour:

Error from SQL Server:
Cannot insert an explicit value into a GENERATED ALWAYS column in table 'TEST_2.dbo.MyTable'. Use INSERT with a column list to exclude the GENERATED ALWAYS column, or insert a DEFAULT into GENERATED ALWAYS column.

Software versions

  • NodeJS: 12.3.0
  • node-mssql: 5.1.0
  • SQL Server: 13

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions