1

I try to push an R table to an SQL Server database, here my script:

dbWriteTable(con, 
             name = "ci_d", 
             value = ci_d, 
             field.types = c(`thing`="varchar(3000)",
                             `notes`="varchar(3000)"
             )

and the error message :

Error in result_insert_dataframe(rs@ptr, values, batch_rows) :
nanodbc/nanodbc.cpp:1655: 22001: [Microsoft][ODBC SQL Server Driver]Troncation à droite de la chaîne de données

Google translation from French: "Right truncation of the data string"

Anyone has an idea to solve this ?

zx8754
  • 52,746
  • 12
  • 114
  • 209
Fabian CO
  • 11
  • 2
  • This is common when the length of the string in the database table is not sufficient to handle this data. You can query `"select column_name, data_type, character_maximum_length from information_schema.columns where table_name='ci_d'"` to see what types (e.g., `char, `nchar`, `varchar`, vs `nvarchar`) and max string length the DBMS thinks the columns should have. – r2evans Feb 05 '21 at 14:00
  • Thanks, I should use varchar(max) in field.types thing. – Fabian CO Feb 05 '21 at 15:03
  • I wasn't saying that, I was suggesting you need to find out what the database thinks that `ci_d` has for column types and size limitations. But if it works, congrats. Is this a new table (created here), or does it exist and you're overwriting it? – r2evans Feb 05 '21 at 15:07
  • It's a new table. To overwrite I need to write overwrite=True. Thanks for your help ! – Fabian CO Feb 06 '21 at 16:32
  • Related, possible duplicate, explanation of the error: https://stackoverflow.com/q/183488/680068 – zx8754 Feb 11 '21 at 10:47

0 Answers0