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

StackOverflow https://stackoverflow.com/questions/14007397

  •  11-12-2021
  •  | 
  •  

Question

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?

Was it helpful?

Solution 2

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 ...

OTHER TIPS

"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.

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.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top