Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RMySQL - dbWriteTable() writes TRUE logical as 0

Tags:

mysql

r

When using dbWriteTable() in the RMySQL package, logical values are written as 0 regardless of value. I would expect that TRUE values would return a 1:

# Setup
# con is a valid MySQLConnection object
> df <- data.frame(string = 'Testing Logical Values', 
                 t_lgl = TRUE, 
                 f_lgl = FALSE, 
                 stringsAsFactors = FALSE)
> df
                  string t_lgl f_lgl
1 Testing Logical Values  TRUE FALSE
> class(df[,2])
[1] "logical"

# Test
# This schema has no tables until dbWriteTable() is called
> dbWriteTable(con,'test_table',df)
[1] TRUE

# Result
> dbReadTable(con,'test_table')
                  string t_lgl f_lgl
1 Testing Logical Values     0     0
> class(dbReadTable(con,'test_table')[,2])
[1] "integer"

Shouldn't the t_lgl value return 1 since it was TRUE and passed to dbWriteTable() as a logical?

like image 688
TK2575 Avatar asked Oct 29 '22 00:10

TK2575


1 Answers

The RMySQL package is being phased out in favour of RMariaDB. Using RMariaDB I am able to successfully write logical values to a MySQL database like this:

con <- dbConnect(RMariaDB::MariaDB(), group = "my-db")

dbWriteTable(con, "test", data.frame(a=T, b=F), overwrite = T)
like image 189
bdforbes Avatar answered Nov 15 '22 06:11

bdforbes