agstudy / rsqlserver

Sql Server driver database interface (DBI) driver for R. This is a DBI-compliant Sql Server driver based on the System.Data.SqlClient.
82 stars 30 forks source link

Bulk Copy only supports varchar destination tables #38

Closed ruaridhw closed 6 years ago

ruaridhw commented 6 years ago

SqlBulkCopy will only allow for uploading files to a destination table comprised of [n]varchar columns only.

The default CSVReader column type is string and if this does not match the table type then SQLBulkCopy throws an error.

CSV column data types need to be set prior to Bulk Copy such that they match the SQL table data types. (See here)

Ideally this should be done dynamically by determining the SQL table types (SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'destTable') and then converting to DataReader types