Correct way of writing conditions into triggers

9 views
Skip to first unread message

patrik....@gmail.com

unread,
Oct 17, 2023, 9:21:27 AM10/17/23
to schedulix
Hello!
I need to start using a bit more complex conditions in triggers for jobs and we need to know what correct syntax is for writing multiple statements within these conditions. 
Is it enough to use "AND" and "OR" between statements?

Ronald Jeninga

unread,
Oct 17, 2023, 10:09:11 AM10/17/23
to schedulix
Hi Patrik,

good to hear from you. I hope everything's OK on your side.

The syntax documentation gives a little help on the condition syntax in the description of the CREATE TRIGGER statement.
The use of AND and OR is as expected (probably). The AND operator is stronger than the OR operator.
Hence, if you want to test if both A OR B OR C and D OR E OR F are true, you'll have to use parenthesis like (A OR B OR C) AND (D OR E OR F), where A,B,C,D,E,F stand for boolean expressions.
 
The current implementation of the condition parser doesn't handle implicit type conversions in a very user-friendly way, unfortunately.
Too often it thinks that the operands are strings, not numbers.
This means that you'll have to use type casts a bit pretty often.
Basically, if you want to know how a certain expression will be evaluated, make the expression as explicit as possible.

Something like

$SUBMITTIME + $EXPRUNTIME < $SYSDATE

is likely to fail, in the sense that it probably won't do the intended numerical comparison.
It is better to protect yourself and write

int($SUBMITTIME) + int($EXPRUNTIME) < int($SYSDATE)

even if that doesn't look very pretty.

Also note that always the full expression is evaluated.
This isn't very nice if you want to test something like

$A == 0 OR $B / $A > 4

In this example the escape is easy: $A == 0 OR $B > 4 * $A 

I hope that helps. But if you need help, you know where to find me.

Best regards,

Ronald
Reply all
Reply to author
Forward
0 new messages