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
Post a Comment