node-mssql
node-mssql copied to clipboard
Bulk upload with a DateTime2 column
I am attempting to perform a bulk upload on a table that requires the additional precision that's included in DateTime2.
Expected behaviour:
Upon bulk insert, I expect the time component of my DateTime2 column to extend to my desired decimal place (6).
Actual behaviour:
A bulk insert instead converts the date to a JavaScript Date object, causing the time component to round to 3 places.
If I perform a direct insert query for a single line (taking the first row of my Table object), everything works as expected.
I was able to trace this to the Table.prototype._makeBulk function in mssql/lib/table.js. The switch resets the value of the row to a Date object for the types of Date, DateTime, and DateTime2, which ultimately cause the truncated seconds decimals.
Software versions
- NodeJS: 18
- node-mssql: 10.0.2
- SQL Server: SQLEXPRESS