0

I'm trying to read tables from my database with DBI package in R :

mydb = dbConnect(MySQL(), user='root', password='*******', dbname='powercurve', host='127.0.0.1')

dbReadTable(mydb,"3.4m140sco")

But apparently the tables name are not allowed in R because I'm getting the error :

Error in .local(conn, statement, ...) : 

could not run statement: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '3.4m140sco' at line 1

If in MySQL database I change the name of that table to something like table1, then I can read it in R easily.

Can somebody help me how could I read those tables in R, because obviously I can not change the names of all the tables.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Ali Hadjihoseini
  • 941
  • 1
  • 11
  • 31
  • Did you check `dbListTables(mydb)` to see if the table name is correct? What if you run `dbGetQuery(mydb, "SELECT * FROM yourtable")` – talat Aug 31 '17 at 15:19
  • @docendodiscimus the names are correct : db_list_tables(mydb) [1] "3.4m140sco" "3.6m118sco" "3.7m144sco" "table1" and the other command I have the same error ! – Ali Hadjihoseini Aug 31 '17 at 15:23

1 Answers1

2

Can the backticks do the trick?

dbReadTable(mydb,"`3.4m140sco`")
Satie
  • 116
  • 1
  • 3