I have a SQL database with two tables. In one all of the data is stored as TEXT, while the other stores columns as TEXT, DOUBLE, TIME, INT, DATE, etc. (I checked using dbDataType(ANSI(), data)
) When I try to join the two in R, though, I get the following warning message:
Warning messages:
1: In result_fetch(res@ptr, n = n) : Column `7.Preferred.Food`: mixed type, first seen values of type integer, coercing other values of type string
When I check the structure of the output dataframe, column 7.Preferred.Food is an integer. The problem is, I want my data imported as a string. Is there a way to compel dbGetQuery to produce only characters? My code is below:
breed= dbGetQuery(con, 'select * from foster
inner join pets
on `ID` = `TAG`')
Preferred Food is an integer in pets
but not in foster
, but switching the order has no effect.
I've tried:
dbExecute(con, "ALTER TABLE file ALTER COLUMN 7.Preferred.Food TEXT")
and got
Error in result_create(conn@ptr, statement) : near "ALTER": syntax error
and
update_query <- paste("update pets",
"ALTER COLUMN 7.Preferred.Food TEXT")
dbSendQuery(con, update_query)
and got
Error in result_create(conn@ptr, statement) : near "ALTER": syntax error
Edit: For work restrictions, I'm stuck with RSQLite and DBI (and the tidyverse); I can't use the whole plethora of extra SQL tools in R.