RandomDude
RandomDude

Reputation: 1141

Import column with large int values from sqlite

I have a sqlite DB that includes columns with int values that are too big for R to handle. Is it still possible to import those columns in R in a way that those big int values will not be converted in a strange way?

What i do so far:

library(DBI)
library(RSQLite)
library(data.table)

# connect to the sqlite file
con <- dbConnect(RSQLite::SQLite(), 'test.sqlite')
# get the perormance_data as a data.frame -> data.table
p1 = dbGetQuery(con,'
SELECT
    Post.post_id,
    Post.created_time
FROM
    Post
            ')
p1 <- as.data.table(p1)

The post_id-column includes large int values for example.

Upvotes: 1

Views: 49

Answers (1)

Joachim Isaksson
Joachim Isaksson

Reputation: 181077

The simplest - as long as you don't need to do arithmetics on the large value - should be to just import it as a string;

library(DBI)
library(RSQLite)
library(data.table)

# connect to the sqlite file
con <- dbConnect(RSQLite::SQLite(), 'test.sqlite')
# get the perormance_data as a data.frame -> data.table
p1 = dbGetQuery(con,'
SELECT
    CAST(Post.post_id AS VARCHAR) post_id,
    Post.created_time
FROM
    Post
            ')
p1 <- as.data.table(p1)
p1

Upvotes: 2

Related Questions