我想直接从python中读取存储在HANA中的表。为此,我使用以下代码:
from hdbcli import dbapi
import pandas as pd
conn = dbapi.connect(
address="address",
port=XYZ,
user="user",
password="password"
)
print (conn.isconnected())
# Fetch table data
stmnt = "select * from '_SYS_NAME'.'part1.part2.part3.part4.part5.part6/table_name'"
cursor = conn.cursor()
cursor.execute(stmnt)
result = cursor.fetchall()
print('Create the dataframe')
问题出在stmnt行中:我尝试了各种放置路径名的方法,以便python可以将其读取为字符串,但没有任何作用。我知道问题不在于技术,因为如果路径很简单并且不包含特殊字符,那么代码就可以工作。
我尝试了以下所有组合(包括其他组合):
stmnt = "select * from '_SYS_NAME'.'part1.part2.part3.part4.part5.part6/table_name'"
stmnt = """select * from '_SYS_NAME'.'part1.part2.part3.part4.part5.part6/table_name'"""
stmnt = "select * from \'_SYS_NAME\'\.\'part1.part2.part3.part4.part5.part6/table_name\'
stmnt = """select * from \'_SYS_NAME\'\.\'part1.part2.part3.part4.part5.part6/table_name\'"""
我得到的错误始终如下:
hdbcli.dbapi.Error: (257, 'sql syntax error: incorrect syntax near "_SYS_NAME": line 1 col 1 (at pos 1)')
从SQL获取的原始路径是:
'_SYS_NAME'.'part1.part2.part3.part4.part5.part6/table_name'
有什么想法我想念的吗?
答案 0 :(得分:1)
您应该反引号:
stmnt = 'select * from "_SYS_BIC"."rwev.dev.bw.project.si.churn/SI_CV_CHU_7_DATA_MODEL"'