Skip to content
Prev 1522 / 1559 Next

RODBC Error when fetching tables: 'Calloc' could not allocate memory

Hi,

I had some similar issues, working with a PostgreSQL/PostGIS database and
RODBC - RODBC seems to have problems dealing with long fields. I tried with
R on both Ubuntu and Windows (PostGIS was always on Ubuntu), but larger
polygons always got truncated. Problems disappeared when I switched over to
DBI and RPostregeSQL. Don't forget to also set 'stringsAsFactors' to false
if you want to read into R instead of just writing out to the database.

HTH

Edward

-----Original Message-----
From: R-sig-DB [mailto:r-sig-db-bounces at r-project.org] On Behalf Of Brad P
Sent: Thursday, July 23, 2015 07:41 AM
To: r-sig-db at r-project.org
Subject: Re: [R-sig-DB] RODBC Error when fetching tables: 'Calloc' could not
allocate memory

Sorry if replying to this is not OK.

I now see that RODBC can not handle cases where length is huge, evidently >
8000, see this:

http://stackoverflow.com/questions/18477994/rodbc-does-not-save-greater-than
-8k-varchar-text-from-a-data-frame

I also noticed that one column in the table previously mentioned had a
length of  2147483647

Anyway, my goal was to pull all tables in and saving them as .rds files.
I wrote a quick work around that identifies which tables have these long
lengths and selects all columns but those columns. This is not ideal, but at
least I get most of the data.

##################################
# get list of all table names
tables <- sqlQuery(con, "SELECT * FROM information_schema.tables") tables <-
subset(tables, subset=TABLE_TYPE!="VIEW") tables <-
as.character(tables$TABLE_NAME)

# for loop to pull in tables 1 at a time for(i in 1:length(tables) ){
  x <- sqlQuery(con, paste("exec sp_columns", tables[i], sep=" ")  )
  if(length(which(x$LENGTH > 8000))>0){
     drop.cols <- as.character( x[which(x$LENGTH > 8000),]$COLUMN_NAME )
     print ( paste(tables[i], "had", paste(drop.cols, collapse=","),
"column(s) dropped", sep=" ") )
     keep.cols <- as.character( x[which(x$LENGTH < 8000),]$COLUMN_NAME )
     dat <- sqlQuery(con, paste( "SELECT", paste(keep.cols, collapse=","),
"FROM", tables[i], sep=" ") )
  }else{
    dat <- try( sqlFetch(con, tables[i]), silent=F)
  }
  print(i)
  print( paste(tables[i]) )
  print( object.size(dat),  units = "auto" )
  saveRDS(dat, paste(tables[i], "rds", sep=".") ) }
##################################

##################################

Cheers!
Patrick
On Wed, Jul 22, 2015 at 8:50 PM, Brad P <bpschn01 at gmail.com> wrote:

            
error.
_______________________________________________
R-sig-DB mailing list -- R Special Interest Group R-sig-DB at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-db