I'm looking for something similar to SQL's LEAST() function.
Since there are binary operators (and a well-defined matching behavior) one would expect there would be min/max as well, but couldn't find such functions.
I'm aware that this is achievable using regex (i.e., min(__name__=~"a|b")
) but would like to avoid such hacks if possible.
I'm pretty sure that's the most efficient way of doing it. If you want to avoid regexes, you could write it instead as:
a < b or b
But it may be more expensive to compute this way. (Unless, of course, you used recording rules instead of min(a)
and min(b)
directly. And maybe even then. You'll just have to benchmark it yourself.)