How to select lines containing specified keywords using the WHERE…LIKE statement in DolphinDB?

18 Views Asked by At

I want to select lines containing one of the strings specified by the vector keyWords in the “index_name“ column. The items of keyWords are not fixed. The following is my script:

keyWords = ['Charging pile','Charging']
tbIndexBasicInfoDemo = select *  from tbIndex where or (like(index_name, stringFormat("%i%",keyWords[0])),like(index_name, stringFormat("%i%",keyWords[1]))) 

However, an error occurs: stringFormat(format, [args...]). : invalid format for %. How to modify my script?

1

There are 1 best solutions below

0
jinwandalaohu On

You can concatenate strings with placeholders as follows:

tbIndex=table(["Charging pile 1","Pile 2"] as index_name)
keyWords = ['Charging pile','Charging']
select * from tbIndex 
where rowOr(each(like{index_name,}, "%"+keyWords+"%"))