Use python list IN postgresql query -
my question similar this have strings instead of integers in list.
my python list:
list = ['a', 'b'] #number of items varies 1 6 i want use list in postgres query this
select * sample sub in ('a', 'b'); i can use tuple(list) ('a', 'b'), not useful when length of list became one. struggling find way convert
['a'] ('a')
['a', 'b'] ('a', 'b')
tried
in[91]: myquery = "select * sample sub in (%s)" % ",".join(map(str,list)) in[92]: myquery out[92]: 'select * sample sub in (a,b,c)' but postgres expects
select * sample sub in ('a', 'b');
use psycopg2 , handle correctly sorts of edge cases haven't thought of yet. specific problem see http://initd.org/psycopg/docs/usage.html#adapt-tuple
Comments
Post a Comment