On this page
- Logical operators
- AND
- OR
- NOT
- Comparison operators
- <
- >
- <=
- >=
- <>
- LIKE
- Type manipulation operators
- 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)
- Date/time functions
- Aggregation functions
- COUNT(expression)
- SUM(expression)
- AVG(expression)
- MIN(expression)
- MAX(expression)
Functions and operators
Last updated on
14 October 2016
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
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
Type manipulation operators
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)
Date/time functions
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
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.