用户定义函数 returns 意外结果
User defined function returns unexpected result
这是我在 whosebug.com 上的第一个问题!
我创建了以下函数来检查 table 在我的 PostgreSQL 数据库中是否存在并在删除之前和之后删除。不幸的是,删除功能没有给我预期的输出。当我用我的输入评估 psql.exists.boolean(x,y)
时,它 return 是 TRUE 的预期结果,但是当我用相同的输入评估 psql.drop(x,y)
时,它没有 return 预期的结果结果。请提供一些指导来修复我的错误功能。
psql.drop<-function(x,y){
table.bad<-x
dbschema<-y
db.location <- c(y,x)
if (psql.exists.boolean(y,x)==TRUE){
dbRemoveTable(con,db.location)
if (psql.exists.boolean(y,x)==TRUE){
msg<-paste("ERROR! The table",dQuote(paste(db.location, collapse = '.')),"still exists!")
} else if (psql.exists.boolean(y,x)==FALSE){
msg<-paste("The table",dQuote(paste(db.location, collapse = '.')),"was successfully removed.")
} else {
msg<-paste("ERROR! Something went wrong.")
}
} else {
msg<-paste("The table",dQuote(paste(db.location, collapse = '.')),"doesn't exist.")
}
return(print(msg))
psql.drop("test_table_1","test_schema_1")
和
psql.exists.boolean<-function(x,y){
# table name to check
table.name<-x
# schema where table is stored
dbschema<-y
# name format in schema
db.location <- c(dbschema, table.name)
# check if table existence in specified location is true
if(dbExistsTable(con,db.location)==TRUE){
return(TRUE)
}else{
return(FALSE)
}
}
psql.exists.boolean("test_table_1","test_schema_1")
您的函数 psql.exists.boolean 首先将 table 名称作为输入,然后是架构名称。
但是当你在 psql.drop 中调用它时,你首先给它模式名称,然后是 table 名称 (psql.exists.boolean(y,x))。
这是我在 whosebug.com 上的第一个问题!
我创建了以下函数来检查 table 在我的 PostgreSQL 数据库中是否存在并在删除之前和之后删除。不幸的是,删除功能没有给我预期的输出。当我用我的输入评估 psql.exists.boolean(x,y)
时,它 return 是 TRUE 的预期结果,但是当我用相同的输入评估 psql.drop(x,y)
时,它没有 return 预期的结果结果。请提供一些指导来修复我的错误功能。
psql.drop<-function(x,y){
table.bad<-x
dbschema<-y
db.location <- c(y,x)
if (psql.exists.boolean(y,x)==TRUE){
dbRemoveTable(con,db.location)
if (psql.exists.boolean(y,x)==TRUE){
msg<-paste("ERROR! The table",dQuote(paste(db.location, collapse = '.')),"still exists!")
} else if (psql.exists.boolean(y,x)==FALSE){
msg<-paste("The table",dQuote(paste(db.location, collapse = '.')),"was successfully removed.")
} else {
msg<-paste("ERROR! Something went wrong.")
}
} else {
msg<-paste("The table",dQuote(paste(db.location, collapse = '.')),"doesn't exist.")
}
return(print(msg))
psql.drop("test_table_1","test_schema_1")
和
psql.exists.boolean<-function(x,y){
# table name to check
table.name<-x
# schema where table is stored
dbschema<-y
# name format in schema
db.location <- c(dbschema, table.name)
# check if table existence in specified location is true
if(dbExistsTable(con,db.location)==TRUE){
return(TRUE)
}else{
return(FALSE)
}
}
psql.exists.boolean("test_table_1","test_schema_1")
您的函数 psql.exists.boolean 首先将 table 名称作为输入,然后是架构名称。 但是当你在 psql.drop 中调用它时,你首先给它模式名称,然后是 table 名称 (psql.exists.boolean(y,x))。