Skip to content

Persisted Computed Columns Break useBulkCopyForBatchInsert #2847

@SpaceCondor

Description

@SpaceCondor

Driver version

13.2.1.jre11

SQL Server version

Microsoft SQL Azure (RTM) - 12.0.2000.8

Client Operating System

Windows 11

JAVA/JVM version

21

Table schema

CREATE TABLE dbo.Products
(
  ProductID int IDENTITY (1,1) NOT NULL,
  QtyAvailable SMALLINT,
  InventoryValue AS QtyAvailable * UnitPrice PERSISTED
  UnitPrice MONEY
);

Problem description

When trying to do a bulk insert using useBulkCopyForBatchInsert for a table with a computed persisted column, it will fail with an error message like:

"Column 3 is invalid. Please check your column mappings."

Digging a bit deeper it is caused by this check:

} else if (0 > cm.destinationColumnOrdinal || destColumnCount < cm.destinationColumnOrdinal) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidColumn"));
Object[] msgArgs = {cm.destinationColumnOrdinal};
throw new SQLServerException(form.format(msgArgs), SQLState.COL_NOT_FOUND, DriverError.NOT_SET,
null);

In the above table it would have a destinationColumnOrdinal of 4 but destColumnCount of 3, leading to that check failing.

Expected behavior

Either have that limitation documented in the known limitations or ignore computed persisted columns in that check.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions