org.apache.spark.sql.catalyst.parser.ParseException: mismatched input '-' - escape characters in select statement python databricks

Viewed 292

I am building a dashboard app with dash using data from my databricks sql database. When trying to run my select statement I get the following error: Caused by: org.apache.spark.sql.catalyst.parser.ParseException: mismatched input '-' expecting {'.', '[',....}

I assume that it's being caused by the column names containing the character '-'. I tried escaping them using first a single, then a double backslash, but that didn't work:

# first try
sql_statement = sql_statement.replace('-','\-')
cursor.execute(sql_statement)

# second try
sql_statement = sql_statement.replace('-','\\-')
cursor.execute(sql_statement)

I received the same error message with another charater as mismatched input: Caused by: org.apache.spark.sql.catalyst.parser.ParseException: mismatched input '' expecting {'.', '[',....}

Before I added the columns containing '-', the data loading worked just fine. Is there a possibility to escape the characters? Manipulating the original name doesnt seem to be the optimal solution... Due to its length, I won't paste the select statement here. Example of the respective column names with '-':

temp_class1:-40----20[°C]

temp_class2:-19---0[°C]

Thanks in advance.

0 Answers
Related