How to append an existing postgresql database table with a new data frame

694 views
Skip to first unread message

varma.a...@gmail.com

unread,
Oct 6, 2015, 10:56:38 AM10/6/15
to sqldf
Hi,

I wanted to append the existing postgresql table structure and data with a new data frame. How to do this?

Need some suggestions.

Thanks and Regards,
Ravi Varma Alluru.

Gabor Grothendieck

unread,
Oct 6, 2015, 4:35:01 PM10/6/15
to sqldf, varma.a...@gmail.com
> I wanted to append the existing postgresql table structure and data with a new data frame. How to do this? 

If X is an existing table in your PostgreSQL database and Y is a data.frame in your R workspace with the same column names then this will insert Y into X:

   library(sqldf)
   library(RPostgreSQL)

   sqldf("insert into X select * from Y")

although typically if you want to manipulate existing tables in a database one would use RPostgreSQL directly.
Reply all
Reply to author
Forward
0 new messages