Вопрос

I was trying to use sqlFetch. The fetch works perfectly when I change the name of my table to have underlines instead of periods. So if I use the command

sqlFetch(conn, "HelloWorld_40")

It works fine. Unfortunately, my friends are all using the real name of the table

sqlFetch(conn, "HelloWorld.40")

But then it crashes and it tells me that

Error in sqlColumns(conn, "HelloWorld.40") : 
'HelloWorld.40': table not found on channel

I'm guessing the period "." is illegal name for a table. But I don't want my friends to change it because it's a lot of people who would be affected. Is there a way I can call the table, or do I have to secretly go to their database, change the name while I use it and then change it back to a period (risking that I will forget, someone will read, blah blah).

Thanks.

Это было полезно?

Решение 2

It is a problem with sqlFetch which parse table name. Unfortunately it did not handle table quotes, so it's search for table 40 in schema HelloWorld. You need to directly call sqlQuery (with quoted table name, brackets for MS SQL Server):

sqlQuery(dbhandle, "SELECT * FROM [HelloWorld.40]") 

Side note: you should specify which database you are using.

Другие советы

put the table name in square brackets:

[HelloWorld.40]

The best delimiter is double quotes -- that should work in most underlying databases:

"HelloWorld.40"

In MySQL, you can also use back ticks (`):

`HelloWorld.40`

In SQL Server, Access, and I think Sybase, you can also use square braces:

[HelloWorld.40]
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top