How to query strings by specifying multiple matching patterns using DolphinDB metaprogramming?

13 views Asked by At

For example, I set the matching pattern to (“NewEnergy“, “Solar“) using the following script:

where (index_full_name like "%NewEnergy%" or index_full_name like "%Solar%")

However, an error occurs: The where clause [any(index_full_name like:R ["%NewEnergy%","%Solar%"])] of a distributed/partitioned sql shouldn't use any aggregate or order-sensitive function.

1

There are 1 answers

0
Shena On

You can use rowOr(index_full_name like:R ["%NewEnergy%", "%Solar%"]) in the where clause, as shown in the following metaprogramming script:

pattern = ["%NewEnergy%", "%Solar%"]
colMeta = "flagName"
whereCond = makeCall(def(colMeta, pattern){return rowOr(colMeta like:R pattern)}, sqlCol(colMeta), pattern)
t = table(["NewEnergy01", "NewEnergy02", "Electricity01"] as flagName, 1 2 3 as val)
sql(sqlCol("val"), t, whereCond).eval()