0 follower

Final Class Yiisoft\Db\Oracle\Builder\ArrayMergeBuilder

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

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

(SELECT JSON_ARRAYAGG(value) AS value FROM (
    SELECT value FROM JSON_TABLE(operand1, '$[*]' COLUMNS(value int PATH '$'))
    UNION
    SELECT value FROM JSON_TABLE(operand2, '$[*]' COLUMNS(value int PATH '$'))
))

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\Oracle\Builder\ArrayMergeBuilder

Constants

Hide inherited constants

Constant Value Description Defined By
DEFAULT_OPERAND_TYPE '' Yiisoft\Db\Oracle\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
{
    $selects = [];
    $operandType = $this->buildOperandType($expression->getType());
    foreach ($expression->getOperands() as $operand) {
        $builtOperand = $this->buildOperand($operand, $params);
        $selects[] = "SELECT value FROM JSON_TABLE($builtOperand, '$[*]' COLUMNS(value $operandType PATH '$'))";
    }
    $orderBy = $expression->getOrdered() ? ' ORDER BY value' : '';
    $unions = implode(' UNION ', $selects);
    return "(SELECT JSON_ARRAYAGG(value$orderBy) AS value FROM ($unions))";
}