Mr. X
Mr. X

Reputation: 11

sending data from R to postgreSQL

I have a data frame SomeData 1 2015-06-05 2 16:00:00 3 19 4 40 5 985 6 69 7 22

I want to send this data into my postgreSQL table. i have done all the pre-requisite stuff. The data base is connected properly. I can easily send data through dbSendQuery. but this dataset is an object data the command for dbSendQuery(con,"Insert into data values('A','b','C')") Here A , b, c refers to data[1], data[2], data[3] i want the values to be exported but it sends them as data[1] data[2] data[3] rather than 1 2 3

Upvotes: 0

Views: 426

Answers (1)

milos.ai
milos.ai

Reputation: 3930

Package RPostgreSQL has dbWriteTable which enables you to store data in command like this:

dbWriteTable(con, "tableName", df, append=TRUE, row.names=0)

Just keep in mind that column names of your data frame (df) have to be same as fields in the db table.

Upvotes: 3

Related Questions