jotNewie
jotNewie

Reputation: 496

Python cannot interprete special characters in path to HANA table (SQL)

I want to read a table stored in HANA directly from python. For that I use the following code:

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')

The problem is in the line stmnt: I tried different ways of puting the path name so that python can read it as a string but none is working. I know the problem is not relying on the technique, because if the path is simple and not containing the special characters then the code works.

I tried all the following combinations (among others):

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\'"""

The error I get is always the following:

hdbcli.dbapi.Error: (257, 'sql syntax error: incorrect syntax near "_SYS_NAME": line 1 col 1 (at pos 1)')

And the original path as I get it from SQL is:

'_SYS_NAME'.'part1.part2.part3.part4.part5.part6/table_name'

Any ideas what I am missing?

Upvotes: 0

Views: 280

Answers (1)

András
András

Reputation: 1390

You should reverse your quotes:

stmnt = 'select * from "_SYS_BIC"."rwev.dev.bw.project.si.churn/SI_CV_CHU_7_DATA_MODEL"'

Upvotes: 1

Related Questions