Functions and Operators
Last updated on
5 October 2022
Drupal's database layer does not provide cross-database abstraction of SQL functions. For portability across supported database engines your code should only use functions known to be part of the ANSI standard and supported across all databases that Drupal supports. The following is a still-incomplete list. The form used here is recommended as other syntax variants may not work on all databases.
Note that the database layer does not whitelist operators, so you may pass a non-standard function, such as REPLACE(), and it will work for databases that support the syntax.
Logical operators
- AND
- OR
- NOT
Comparison operators
- <
- >
- <=
- >=
- <>
- LIKE
- REGEXP
String functions and operators
- CONCAT(string1, string2)
- SUBSTRING(string, from, length)
- SUBSTRING_INDEX(string, delimiter, count)
- LENGTH(string)
Mathematical functions and operators
- GREATEST(num1, num2)
- POW(num1, num2)
- LOG(base, value)
Aggregation functions
- COUNT(expression)
- SUM(expression)
- AVG(expression)
- MIN(expression)
- MAX(expression)
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion