python中带有变量的impala查询-与%symbol混淆?

e4eetjau  于 2021-06-26  发布在  Impala
关注(0)|答案(0)|浏览(215)

我有以下从python调用的impala查询,运行良好。

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)

然后,如果我对查询进行如下修改:

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)

我得到以下错误:

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

我猜python和 %col_C like 'AB%' . 我想知道是否有办法解决这个问题?谢谢!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题