diff --git a/application/Espo/ORM/Query/Part/Expression.php b/application/Espo/ORM/Query/Part/Expression.php index fa66cdd0ab..5b47f4ef3e 100644 --- a/application/Espo/ORM/Query/Part/Expression.php +++ b/application/Espo/ORM/Query/Part/Expression.php @@ -48,7 +48,7 @@ class Expression implements WhereItem throw new RuntimeException("Expression can't be empty."); } - if (substr($expression, -1) === ':') { + if (str_ends_with($expression, ':')) { throw new RuntimeException("Expression should not end with `:`."); } @@ -653,6 +653,22 @@ class Expression implements WhereItem return self::composeFunction('ROUND', $number, $precision); } + /** + * 'GREATEST' function. A max value from a list of expressions. + */ + public static function greatest(Expression ...$expressionList): self + { + return self::composeFunction('GREATEST', ...$expressionList); + } + + /** + * 'LEAST' function. A min value from a list of expressions. + */ + public static function least(Expression ...$expressionList): self + { + return self::composeFunction('LEAST', ...$expressionList); + } + /** * 'AND' operator. Returns TRUE if all arguments are TRUE. */