I can do a regular variable substitution in mysql/python using:
cursor.execute("SELECT DATE_FORMAT(`item_start`,'%%Y-%%m') AS ym,
count(*) as num
from t_calendar_data
where Concat(item_subject, ' ', item_text_body) like %s
group by ym",
("%{}%".format(i),))
but I'm not sure how to use REGEXP with:
[[:<:]]VARIABLE[[:>:]]
I've tried various forms of:
cursor.execute("SELECT DATE_FORMAT(`item_start`,'%%Y-%%m') AS ym,
count(*) as num from t_calendar_data where Concat(item_subject, ' ',
item_text_body) REGEXP %s group by ym", ("[[:<:]]%{}%
[[:>:]]".format(i),))
with no success. How do I wrap the regex (assuming I'm putting REGEXP in the correct spot)?
Wiktor's response worked perfect. I had to remove my extra %.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.