0

I am trying to make a query using sqlalchemy

df=pd.read_sql_query('SELECT * FROM `all-data`.indicators_ft \
WHERE country= "United States" AND name="Average Hourly Earnings % m/m" ', engine)

However that specific query doesnt work. I isolated the problem and it is in the expression "Average Hourly Earnings % m/m". I suspect it is because of the % or / symbol that would need to be escaped. But how to do that? I tried backslashes but they didnt work.

subsidiary question: I also tried NAME LIKE "Average Hourly Earnings%" to bypass the problem but it didnt work either - how to do a LIKE query in sqalchemy?

NB: I tried both those queries in mysql workbench and they did work.

Thx!

jim jarnac
  • 4,804
  • 11
  • 51
  • 88
  • Found the answer here: http://stackoverflow.com/questions/3037581/how-do-i-escape-from-python-mysql-query % sign is escaped by using %% – jim jarnac Dec 27 '16 at 11:30

1 Answers1

0

You can use multi-line string like so:

'''
   SELECT * FROM `all-data`.indicators_ft 
   WHERE country= "United States" AND name="Average Hourly Earnings % m/m
'''
Disciples
  • 662
  • 1
  • 6
  • 15