8

I set up an ODBC connect to a Netezza (SQL database). The connection is fine. However, R only pulls out 256 rows by default and restricts the number of rows it can pull out.

If I ran the query in Netezza, it would return a total number of rows (300k). I am expecting the same number of rows in R. However, it only returned 256 rows quite a bit short from 300k.

The driver I am using NetezzaSQL version 7.00.02 NSQLODBC.DLL

I tried to change the pre-fetch count to zero in the "Drivers Option' from Control Panel > Administrative Tools > Data Sources(OBBC) > System DNS

It didn't work. Any ideas?

topchef
  • 19,091
  • 9
  • 63
  • 102
Luo Lei
  • 649
  • 2
  • 9
  • 19

3 Answers3

8

I think RODBC acts poorly with Netezza. A solution http://datamining.togaware.com/survivor/Database_Connection.html

just add believeNRows=FALSE to either your sqlQuery or odbcConnect call (use the later if you also use sqlFetch.

Daniel Sparing
  • 2,163
  • 15
  • 20
Luo Lei
  • 649
  • 2
  • 9
  • 19
  • Correct, just add the argument to your query, for example `results = sqlQuery(dbhandle, "SELECT * FROM TABLE", believeNRows=FALSE)` – DavidJ Aug 26 '14 at 14:29
2

You can also try using JDBC driver:

library(RJDBC)
drv <- JDBC("org.netezza.Driver", "nzjdbc.jar", "'")

conn <- dbConnect(drv, "jdbc:netezza://host:5480/database", "user", "password")

res <- dbSendQuery(conn, "select * from mytable")

That way you don't have to deal with DSNs, etc.

Alex Vorobiev
  • 4,349
  • 21
  • 29
  • 2
    Alex, I've tried this method using nzjdbc.jar on a Mac and am still getting 256 rows back. Any ideas? – Frank P. Aug 04 '14 at 20:32
  • @FrankP., 256 is the default length of the pre-fetch buffer for the driver. Did you download the data using `fetch(res, n = -1)`? -1 would force all the records to be retrieved. – Alex Vorobiev Aug 06 '14 at 15:51
  • When I do fetch(res, n = -1) I still get 256 rows. If I do fetch(res, n = 10) and then fetch(res, n = -1) then I get 10 rows first and then 246 rows. So it seems the query only ever contains 256 rows. – Stuart Apr 10 '20 at 10:26
  • This works for me if you change the SQL query to explicitly add a high limit RJDBC::dbGetQuery(conn, "select * from mytable LIMIT 2147483647") – Stuart Apr 10 '20 at 13:15
1

I know this is kind of out-dated but the problem is not with the RODBC package. The problem lies in how you set up the ODBC connection if you configure the connection in windows you'll see a last tab in the settings where you can specify the amount of rows it'll fetch. And the default is on 256.