function Select::addExpression

Same name in this branch
  1. 9 core/modules/pgsql/src/Driver/Database/pgsql/Select.php \Drupal\pgsql\Driver\Database\pgsql\Select::addExpression()
Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Database/Driver/pgsql/Select.php \Drupal\Core\Database\Driver\pgsql\Select::addExpression()
  2. 8.9.x core/lib/Drupal/Core/Database/Query/Select.php \Drupal\Core\Database\Query\Select::addExpression()
  3. 10 core/modules/pgsql/src/Driver/Database/pgsql/Select.php \Drupal\pgsql\Driver\Database\pgsql\Select::addExpression()
  4. 10 core/lib/Drupal/Core/Database/Query/Select.php \Drupal\Core\Database\Query\Select::addExpression()
  5. 11.x core/modules/pgsql/src/Driver/Database/pgsql/Select.php \Drupal\pgsql\Driver\Database\pgsql\Select::addExpression()
  6. 11.x core/lib/Drupal/Core/Database/Query/Select.php \Drupal\Core\Database\Query\Select::addExpression()

Overrides SelectInterface::addExpression

1 call to Select::addExpression()
Select::orderRandom in core/lib/Drupal/Core/Database/Query/Select.php
Orders the result set by a random value.
1 method overrides Select::addExpression()
Select::addExpression in core/modules/pgsql/src/Driver/Database/pgsql/Select.php
Adds an expression to the list of "fields" to be SELECTed.

File

core/lib/Drupal/Core/Database/Query/Select.php, line 588

Class

Select
Query builder for SELECT statements.

Namespace

Drupal\Core\Database\Query

Code

public function addExpression($expression, $alias = NULL, $arguments = []) {
    if (empty($alias)) {
        $alias = 'expression';
    }
    $alias_candidate = $alias;
    $count = 2;
    while (!empty($this->expressions[$alias_candidate])) {
        $alias_candidate = $alias . '_' . $count++;
    }
    $alias = $alias_candidate;
    $this->expressions[$alias] = [
        'expression' => $expression,
        'alias' => $alias,
        'arguments' => $arguments,
    ];
    return $alias;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.