7 query.inc public UpdateQuery::expression($field, $expression, array $arguments = NULL)

Specifies fields to be updated as an expression.

Expression fields are cases such as counter=counter+1. This method takes precedence over fields().


$field: The field to set.

$expression: The field will be set to the value of this expression. This parameter may include named placeholders.

$arguments: If specified, this is an array of key/value pairs for named placeholders corresponding to the expression.

Return value

UpdateQuery The called object.


includes/database/query.inc, line 1137
Non-specific Database query code. Used by all engines.


General class for an abstracted UPDATE operation.


public function expression($field, $expression, array $arguments = NULL) {
  $this->expressionFields[$field] = array(
    'expression' => $expression,
    'arguments' => $arguments,

  return $this;


Here is an example to set the value of one column to the same as another column:

->expression('column1', 'column2')

which is equivalent to the following SQL:

UPDATE 'tablename' SET column1=column2;

Here is an example of how to add 1 to an integer field. In this example MYTABLE is the schema you want to update, MYFIElD is the field within that table you want to update, and $SOMEVARIABLE is whatever you are using to select the correct row in that table.

      ->expression('MYFIELD', 'MYFIELD + 1')
      ->condition('MYFIELD', $SOMEVARIABLE)