我有一個R代碼的文件,它建立了幾個數據框,然後嘗試將它們存儲到Postgres數據庫中。這通常失敗,失敗的代碼片段如下。R;如何解決「過期的PostgreSQLConnection」錯誤?
require ("RPostgreSQL")
drv <- dbDriver("PostgreSQL")
res <- dbConnect (drv, dbname = db,
host = "localhost", port = 5432,
user = "postgres", password = pw)
table_name <- "gemeenten"
print (c ("adding ", table_name))
if (dbExistsTable (con, table_name)) dbRemoveTable (con, table_name) ### Error!
result <- dbWriteTable (con, table_name, gemeenten)
我得到的錯誤是:
Error in postgresqlQuickSQL(conn, statement, ...) :
expired PostgreSQLConnection
,並在dbExistsTable
測試出現錯誤。當我撥打dbListConnections (PostgreSQL())
時,每次連接數增加1,呼叫dbDisconnect (con)
不會減少此數字。
當我試圖從.Profile文件創建驅動程序之前,我得到了這個錯誤,我可以解決這個問題是刪除drv
變量並重新分配它。我在創建這個表格方面成功了兩次,但我無法重建爲什麼發生這種情況。有誰知道我做錯了什麼?