Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python list of String to SQL IN parameter

Tags:

python

list

mysql

I have this query in python:

ssim_group = [S1200,S1300]

query = '''select WIPMessageCnt from waferdata where recipename in (%s) and equipment = ?
                             and runtype = ? order by  stopts desc limit 1''' % (','.join(ssim_grp))

print query

Current result

select WIPMessageCnt from waferdata where recipename in (S1200,S1460) and equipment = ? and runtype = ? order by stopts desc limit 1

Expected result should be like this

select WIPMessageCnt from waferdata where recipename in ('S1200','S1460') and equipment = ? and runtype = ? order by stopts desc limit 1

The list should have single qoutation on each element when I try to put them inside the IN parameter on SQL. How can I achieve this?

like image 522
ellaRT Avatar asked Sep 21 '26 15:09

ellaRT


1 Answers

ssim_group = ['S1200', 'S1300']
query = '''select WIPMessageCnt from waferdata where recipename in ('%s') and equipment = ? and runtype = ? order by  stopts desc limit 1''' % ("','".join(ssim_group))
like image 144
yanghaogn Avatar answered Sep 23 '26 06:09

yanghaogn