Community Documentation

Functions and operators

Last updated January 30, 2013. Created by Damien Tournoud on April 16, 2010.
Edited by misjao, rooby, agentrickard, Crell. Log in to edit this page.

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)