How to check whether a column in a table is strictly monotonically increasing?

56 Views Asked by At

I want to check whether a column in a table is strictly monotonically increasing. How can I do this? Is the expression a>=prev(a) valid in DolphinDB? Does anyone know a built-in function for this purpose? If so, can you share some best practices? Thanks in advance.

2

There are 2 best solutions below

0
Smalllpotato On BEST ANSWER

You can try isSorted, for example:

t = table(`a`b`c`a`d`e as sym, 1 3 3 5 6 7 as id)
select isSorted(id) from t // true

t = table(`a`b`c`a`d`e as sym, 4 3 3 5 6 7 as id)
select isSorted(id) from t // false
0
Hanwei Tang On

You expression is OK. To get the final result:

all(a >= prev(a))

Be careful if any NULL in a.