Extracting Table from HANA using R

帅比萌擦擦* 提交于 2019-12-23 04:26:40

问题


This is the table I am trying to grab. From my HANA Database however I keep getting the below error. I know the table exists as I have pulled it in from Qlikview.

From Qlikview I pull in the table using the below syntax

"_MY_SCHEMA_"."My.Table.Name/Table_ONE"

When I try to do the same thing in R using I use the following to grab the same table

mydate <- sqlFetch(myconn, "_MY_SCHEMA.My.Table.Name/Table_ONE")

This is the error that I get

Error in odbcTableExists(channel, sqtable)
: table not found on channel

回答1:


This problem is caused by the way STRINGS are encapsulated in quotes. In this scenario this happens in two levels:

  1. R command parameter (sqlFetch ( connection-object-parameter, sql-string-parameter)
  2. HANA SQL where the literal string for the table name is required

You used the double-quotes encapsulation for both steps. In each of those two steps the strings get extracted from the parameter you used, which includes the removal of the outermost encapsulation markers which are the double-quotes here. So, after step 1 the double quotes are gone and HANA receives a string without them.
This is OK, as long as you don't actually require the double-quotes for your identifiers, but in your example you actually do. (case sensitive identifiers with special characters like / or . require the double quotes).

The solution to this is rather simple: R allows both single (') and double (") quotes to be used for string encapsulation.
Just use single quotation marks in R to hand over the string:

mydate <- sqlFetch(myconn, '_MY_SCHEMA."My.Table.Name/Table_ONE"')

Notice: you still have to encapsulate "My.Table.Name/Table_ONE" in double quotation marks so that HANA will handle this identifier correctly.

For the connection R to HANA there are also a couple of blogs out:

  • HANA quick note checking my connections ...
  • HANA meets R


来源:https://stackoverflow.com/questions/41875600/extracting-table-from-hana-using-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!