I am working with python plugins.I used list to store some values as below:
known_stn.append('1')
known_stn.append('2')
My query is
query=("SELECT survey, station FROM stat WHERE stat.station IN (%s) AND station.survey = '2011410'" %known_stn)
Error occurs for WHERE station.station IN (['1', '2']),as list contains [] brackets.
I tried replacing those brackets but they doesnt get replace.
Is there any other data structure to use?? Or way out to replace square brackets…
You need to format your list as a string before you substitute it into your template string:
http://docs.python.org/library/stdtypes.html#str.join
map(str,known_stn)converts the elements themselves to a string, before joining.Also, heed the warnings about SQL injection.