I dont know if my question can represent what I need
I have this code :
i<-0 j<-0
for(i in 0:m){ j<- j+1 neighborhood <- fn$sqldf("SELECT object2
FROM distance WHERE object1=('$j') AND neighbor=TRUE UNION SELECT
object1 FROM distance WHERE object2=('$j') AND neighbor=TRUE ")
for (neighbor in neighborhood){
fn$sqldf(" INSERT INTO neighborhoods(object,neighborhood)
VALUES ('$neighbor','$neighbor')")
The result of neighborhood is (8,10,11)
I want to get result in table neighborhoods like:
(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 8.10, 8.11, 9.9,
etc
but I always get this Error in postgresqlExecStatement(conn, statement, ...) :
RS-DBI driver: (could not Retrieve the result : ERROR: invalid input syntax for integer: "c(8, 10, 11)" LINE 1: ...TO neighborhoods(object,neighborhood) VALUES ('8','c(8, 10, ... ^ )
I just find out, how to get the result I want with some loop like this
i <- 0 j <- 1 for (i in 0:m){ core <- fn$sqldf("SELECT core FROM core_point WHERE gid=('$j')") if (core = FALSE){
fn$sqldf("insert into neighborhoods(object, neighborhood) values ('$j', '$j'") j<-j+1 } if (core ==TRUE){ neighborhood <- fn$sqldf("SELECT object2 FROM distance WHERE object1=('$j') AND neighbor=TRUE UNION SELECT object1 FROM distance WHERE object2=('$j') AND neighbor=TRUE ")a <-fn$sqldf("select totalneighborhoods from core_point where gid='$j'") a <- as.numeric(a) for(k in 1:a){ o<- neighborhood[k,1] fn$sqldf(" INSERT INTO neighborhoods(object,neighborhood) VALUES ('$j','$o')") k<- k+1 } j<- j+1 } }
But I think it will gain the process, any idea? *sorry if my english is not good