python - Adding list elements to WHERE clause -


i want add condition where clause:

stmt = 'select account_id asmithe.data_hash percent < {};'.format(threshold)

i have variable juris list. value of account_id , juris related in when account_id created, contains substring of juris.

i want add query condition needs match of juris elements. add ...and account_id '{}%'".format(juris) doesn't work because juris list.

how add elements of list where clause?

use regex operator ~:

 juris = ['2','7','8','3']  'select * tbl id ~ \'^({})\''.format('|'.join(juris)) 

which leads query:

select * tbl id ~ '^(2|7|8|3)' 

this brings rows id start with of 2,7,8 or 3. here fiddle it.

if want id start 2783 use:

select * tbl id ~ '^2783' 

and if id contains of 2,7,8 or 3

select * t id ~ '.*(2|7|8|3).*' 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -