Connect R and Netezza using RJDBC

后端 未结 2 603
孤街浪徒
孤街浪徒 2021-01-23 08:23

I´m trying to connect R with Netezza using the JDBC driver.

I manage to connect succesfully with the database, but the results are not corretc.

# Here ar         


        
2条回答
  •  天命终不由人
    2021-01-23 09:11

    Based on Alex answer i wrote this function to use rtrim in all variables.

    query_nzz <- function(con, select="select * ", from="", where = "", limit = " 10000; "){
      options(scipen=666)
    
      # Get variable Names
      query_names = paste(select, " from ",from, where, sep = " ")
      names <- dbGetQuery(con, paste(query_names,"limit 1;", sep= " "))
      names <- names(names)
    
      # Trim spaces
      select <- paste0("trim(",names,") as ", names, collapse = ",")
    
      query = paste0("select ", select, " from ", from, where, " limit ",deparse(limit),";")
      data = dbGetQuery(con, query)
      data
    }
    

    Function usage

      dt <- query_nzz(
        con,
        select = "select * ",
        from = "DATABASE.TABLENAME",
        where = "",
        limit = 100000
      )
    

提交回复
热议问题