RS-DBI driver warning: (unrecognized MySQL field type 7 in column 1 imported as character)
Asked Answered
H

3

5

I'm trying to run a simple query that works with MySQL or other MySQL connector API's,

SELECT * FROM `table` WHERE type = 'farmer'

I've tried various methods using the RMySQL package and they all get the same error RS-DBI driver warning: (unrecognized MySQL field type 7 in column 1 imported as character)

Type = 'farmer'
(Query<-paste0("SELECT * FROM `table` WHERE type = '%",Type,"%'")) 
res<-dbGetQuery(con, Query)

Query<-paste("SELECT * FROM `table` WHERE type = \'farmer\'")



Query<-paste("SELECT * FROM `table` WHERE type = 'farmer'")

What am I doing wrong?

Hoffert answered 22/12, 2012 at 23:16 Comment(0)
S
0

Looks like the db schema has something in column which is of type 7 -- and that type appears to be unknown to the RMySQL driver.

I try to exclude column one in the query, or cast it at the select * ... level eg via something like

 select foo as character, bar, bim, bom from 'table' where ...
Stokehole answered 22/12, 2012 at 23:21 Comment(0)
M
11

"type" is a keyword in MYSQL. Surround the it with backticks to escape field names.

SELECT * FROM `table` WHERE `type` = 'farmer'

Also you probably have a time stamp column in your table. R is known to not recognize that column type. Convert it to a unix time stamp in the portion of the SQL statement.

Maible answered 23/12, 2012 at 14:37 Comment(1)
plus one for the bit about the timestamp.Kreiner
S
0

Looks like the db schema has something in column which is of type 7 -- and that type appears to be unknown to the RMySQL driver.

I try to exclude column one in the query, or cast it at the select * ... level eg via something like

 select foo as character, bar, bim, bom from 'table' where ...
Stokehole answered 22/12, 2012 at 23:21 Comment(0)
T
0

To be clear, when I encountered this error message, it was because my data field was a time stamp.

I verified this by changing my query to SELECT created_at FROM ... which caused the error. I also verified this by changing the query not to include the column names that were timestamps, then I had no errors.

Note too, that the error message counts columns starting from 0 (instead of 1 as R does)

IMHO, the answer is you aren't doing anything wrong, but it's something that needs to be fixed in RMySQL.

The workaround is after you read in your data, you need to call one of the several possible character to datetime conversion functions. (Which one depends on what you want to do with the time stamp exactly.)

Tody answered 29/9, 2018 at 0:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.