I have been trying to figure out how to write a data frame to a volatile table on a teradata server. I was trying to follow this example but am not having a lot of luck.
Here's my attempt:
pass = getPass(msg = "Network Password:")
edv = odbcConnect(dsn = "", uid = "", pwd = pass)
rm(pass)
# So I believe we'll first have to create a table:
quer1 = paste("CREATE VOLATILE TABLE testdat",
"(op_sys INT, enter_final_icu VARCHAR(20), mrn VARCHAR(8))",
"UNIQUE PRIMARY INDEX(op_sys)",
"ON COMMIT PRESERVE ROWS;")
sqlQuery(edv, quer1)
# This returns a zero row table, so far so good:
quer2 = "select top 10 * from testdat"
sqlQuery(edv, quer2)
# See if we can save the data:
columnTypes <- list(op_sys = "INT",
enter_final_icu = "VARCHAR(20)",
mrn = "VARCHAR(8)")
# pop is a data.frame with 3 the same 3 columns as in the definition of testdat
sqlSave(channel = edv,
dat = pop,
tablename = 'testdat',
append = TRUE,
rownames = FALSE,
varTypes = columnTypes)
sqlUpdate(channel = edv,
dat = pop,
tablename = 'testdat')
The sqlSave
statement tells me that 'table testdat already exists' which is what I thought I wanted to do. I thought update = TRUE
would let me add data to the table...
The sqlUpdate
statement tells me that 'testdat: table not found' which is pretty odd given that I'm able to query it.
Any suggestions would be appreciated, thanks!