greenplum-db / PivotalR-archive

An convenient R tool for manipulating tables in PostgreSQL type databases and a wrapper of Apache MADlib.
https://pivotalsoftware.github.io/gp-r/
125 stars 53 forks source link

dbWriteTable seems to be broken when using PivotalR package #53

Closed pottegil closed 7 years ago

pottegil commented 7 years ago

I need to write an R data.frame back to a GreenPlum database after doing some work on it. This is usually no problem in something like RMYSql, you use the method dbWriteTable(connection, "table name", df, append = T, , row.names = FALSE , overwrite = F, allow.keywords = FALSE) and boom, data into the table.

When I try to do this from the PivotalR connection I get the following error

Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘dbWriteTable’ for signature ‘"numeric", "character"'

To reproduce

require(PivotalR)
cid <- db.connect(port = 5432, host = host, dbname = dbname, user = user, password = password)
db.q('create table test_table as select * from schema.tableA limit 10;', conn.id = cid)
results_to_append <- db.q('select * from schema.tableA limit 10;', conn.id = cid)
dbWriteTable(cid, "schema.test_table", results_to_append, append = T, , row.names = FALSE , overwrite = F, allow.keywords = FALSE)

Does the PivotalR package actually implement data loading? I can't find any documentation.

iyerr3 commented 7 years ago

You could use the as.db.data.frame function:

as.db.data.frame(results_to_append, 'schema.test_table', append = T, row.names = FALSE , overwrite = F, conn.id=cid)
pottegil commented 7 years ago

Oh, snap! That worked like a charm, for some reason I was just not understanding that as.db.data.frame was the function. Thanks for the help @iyerr3.