DBI - field.types = varchar(max) for all columns ?

Hi everybody,

I try to write a dataframe in a SQL Server table with all fields with varchar(max) but i don't find the correct code... My dataframe contains lot of fields, so it's quiet long to specify type for each field...

My R code below :

dbWriteTable(con, 
             name = "ci_td", 
             value = ci_tdip,
             file_encoding ="latin-1",
             field.types="varchar(max)", # here is my problem, I know this is not correct, it's just for explain...
             overwrite=TRUE)

Any idea please ?

Thank you for your help,

1 Like

I think you are asking for something like

#for example data 
ci_tdip <- iris


(myvec <- rep("varchar(max)",ncol(ci_tdip )))
names(myvec) <- names(ci_tdip )
myvec

dbWriteTable(con, 
             name = "ci_td", 
             value = ci_tdip,
             file_encoding ="latin-1",
             field.types=myvec
             overwrite=TRUE)

but feel free to clarify

1 Like

It works fine thank you !

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.