0 follower

Final Class Yiisoft\Db\Pgsql\Builder\ArrayMergeBuilder

InheritanceYiisoft\Db\Pgsql\Builder\ArrayMergeBuilder » Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder

Builds SQL expressions which merge arrays for {@see ArrayMerge} objects.

ARRAY(SELECT DISTINCT UNNEST(operand1::int[] || operand2::int[]))::int[]

Protected Methods

Hide inherited methods

Method Description Defined By
buildFromExpression() Builds a SQL expression which merges arrays from the given {@see ArrayMerge} object. Yiisoft\Db\Pgsql\Builder\ArrayMergeBuilder

Method Details

Hide inherited methods

buildFromExpression() protected method

Builds a SQL expression which merges arrays from the given {@see ArrayMerge} object.

protected string buildFromExpression ( \Yiisoft\Db\Expression\Function\ArrayMerge $expression, array &$params )
$expression \Yiisoft\Db\Expression\Function\ArrayMerge

The expression to build.

$params array

The parameters to bind.

return string

The SQL expression.

                protected function buildFromExpression(MultiOperandFunction $expression, array &$params): string
{
    $typeHint = $this->buildTypeHint($expression->getType());
    $builtOperands = [];
    foreach ($expression->getOperands() as $operand) {
        $builtOperands[] = $this->buildOperand($operand, $params) . $typeHint;
    }
    $orderBy = $expression->getOrdered() ? ' ORDER BY 1' : '';
    return 'ARRAY(SELECT DISTINCT UNNEST(' . implode(' || ', $builtOperands) . ")$orderBy)$typeHint";
}