[R] quoting a table name due to a special character in sqlQuery (RODBC)

Stefan Uhmann stefan.uhmann at googlemail.com
Tue Sep 15 16:52:27 CEST 2009


Dear List,

I have a problem with RODBC on a Paradox-DB, sqlQuery, and special 
characters in table names. Unfortunately, some of the latter include the 
underscore <_>. And I am not able to change them.

That's not a problem, when I quote the table name:
 > sqlQuery(channel2, 'SELECT * FROM "anmeldung-alt"')
Btw, if I swap ' and " it does not work:
 > sqlQuery(channel2, "SELECT * FROM 'anmeldung-alt'")
[1] "HY000 -3003 [Microsoft][ODBC Paradox Driver] Syntaxfehler in 
Abfrage. Die Abfrage ist unvollständig."
[2] "[RODBC] ERROR: Could not SQLExecDirect 'SELECT * FROM 
'anmeldung-alt''"

It gets nasty, when I try to build a function and to substitute the 
'SELECT * FROM "anmeldung-alt"' with a paste():
 > tabelle
[1] "anmeldung-alt"
 > paste('select * from ', '"', tabelle, '"', sep="")
[1] "select * from \"anmeldung-alt\""
 > gsub('\"', '"', paste('select * from ', '"', tabelle, '"', sep=""))
[1] "select * from \"anmeldung-alt\""

Can anybody point me into the right direction, please?

Thanks in advance,
Stefan




More information about the R-help mailing list