R语言list或data.table或data.frame类型数据快速写入数据库保存
斜博超
2023-12-01
totalCjTable<-function(){
colnames(totalCj)<-c(
'jzdm','xbdm', 'mzdm', 'zzmmdm', 'kldm', 'kslbdm', 'bylbdm', 'byxxdm', 'wyyzdm',
'wytlbz', 'kslx', 'nf', 'ssdm', 'ksh', 'wl', 'tcj', 'full_score', 'tcj_ss_z',
'tcj_jz_z', 'yblqfsx', 'eblqfsx', 'sblqfsx')
aggTableName <- 'totalCj'
library(RPostgreSQL)
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, user="postgres", password="123", host="localhost", port="5432", dbname="totalCj_table")
postgresqlpqExec(con, "SET client_encoding = 'gbk'")
dbWriteTable(con, aggTableName, totalCj, overwrite=TRUE)
dbDisconnect(con);
}