Function Expressions

October 16, 2025 ยท View on GitHub

The library provides several classes to represent SQL functions as expressions.

Important

The functions quote string values as column names, except when they contain a parentheses (, in which case they will be treated as raw SQL expressions. Use Value object for string values.

For example, new Longest(new Value('short'), 'column_name') will be rendered as LONGEST('short', "column_name").

The following expression classes are available:

ArrayMerge

The ArrayMerge expression allows you to merge two or more arrays into one array.

new ArrayMerge(['a', 'b'], 'array_col', $db->select(['array_col'])->from('table'));

Greatest

The Greatest expression allows you to find the largest value in a list of expressions.

new Greatest(1, 'int_col', $db->select(['int_col'])->from('table'));

Least

The Least expression allows you to find the smallest value in a list of expressions.

new Least(1, 'int_col', $db->select(['int_col'])->from('table'));

Length

The Length expression allows you to find the length of a string.

new Length(new Value('string'));
new Length('string_col');
new Length($db->select(['string_col'])->from('table'));

Longest

The Longest expression allows you to find the longest string in a list of expressions.

new Longest(new Value('short'), 'string_col', $db->select(['string_col'])->from('table'));

Shortest

The Shortest expression allows you to find the shortest string in a list of expressions.

new Shortest(new Value('short'), 'string_col', $db->select(['string_col'])->from('table'));