我是 R 新手,并试图在 Postgresql 中插入 R 数据框。每当我尝试执行我的 rscripts.R 时,我都会收到以下错误:
“在 postgresqlWriteTable(conn, name, value, ...) 中:表 customervalidation 存在于数据库中:aborting assignTable”
表customervalidation 已存在于postgresql 中,我正在尝试在此表中插入SampleData.csv 的内容。csv 的所有标题都已经存在于表中,并且它们都是小写的。
命令行参数
./script.R batch SampleData.csv yes no
rscripts.R 内容
#!/usr/bin/Rscript
options(echo=TRUE) # if you want see commands in output file
args <- commandArgs(trailingOnly = TRUE)
print(args)
# trailingOnly=TRUE means that only your arguments are returned, check:
# print(commandsArgs(trailingOnly=FALSE))
batchIndicator <- tolower(args[1])
filename <- args[2]
isHeaderPresent <-args[3]
isRunTheBatch<-args[4]
rm(args)
#Library files
library(RPostgreSQL)
#now check whether it is immediate or batch.
# if it is immediate then real time prediction needs to prepare.
# if it is batch then whole batch set needs to prepare and keep the results in a separate file.
if(isHeaderPresent == "yes")
{
header = TRUE
}else
{
if(isHeaderPresent == "no"){
header = FALSE
}
}
print(paste("Processing for Batch mode for filename ", filename))
# Start body for other function
data <-read.csv(filename,header = header, sep=",")
drv <- dbDriver("PostgreSQL")
con <- dbConnect(PostgreSQL(), dbname = "customervalidation", host = "localhost", port =5432 , user = "user", password = "pwd")
dbWriteTable(con,"customervalidation",data,row.names=FALSE)
#end body for other function
请帮助我找出这里缺少的错误。