I have the following Impala query called from Python, working fine.
reference_ts = "2017-03-11 00:00:00"
q = """
select col_A, col_B, trunc(my_timestamp, 'D') as arrival_wk
from my_table
where my_timestamp < "%s"
""" % (reference_ts)
my_df = my_conn.exec_query(q)
Then if I modify the query a little bit like below:
q1 = """
select col_A, col_B, trunc(my_timestamp, 'D') as arrival_wk
from my_table
where my_timestamp < "%s"
and col_C like 'AB%'
""" % (reference_ts)
my_df1 = my_conn.exec_query(q1)
I got the following error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-81-be1bb3b139a5> in <module>()
15
---> 16 """ % (reference_ts)
17
ValueError: unsupported format character ''' (0x27) at index 303
I am guessing Python is confused with the %
in col_C like 'AB%'
. I am wondering if there is a way to resolve this problem? Thanks!