Final Class Yiisoft\Db\Mysql\Builder\ArrayMergeBuilder
| Inheritance | Yiisoft\Db\Mysql\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 json PATH '$')) AS t
UNION
SELECT value FROM JSON_TABLE(operand2, '$[*]' COLUMNS(value json PATH '$')) AS t
) t)
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| buildFromExpression() | Builds a SQL expression which merges arrays from the given {@see ArrayMerge} object. | Yiisoft\Db\Mysql\Builder\ArrayMergeBuilder |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| DEFAULT_OPERAND_TYPE | 'json' | Yiisoft\Db\Mysql\Builder\ArrayMergeBuilder |
Method Details
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
{
$operandType = $this->buildOperandType($expression->getType());
$selects = [];
foreach ($expression->getOperands() as $operand) {
$builtOperand = $this->buildOperand($operand, $params);
$selects[] = "SELECT value FROM JSON_TABLE($builtOperand, '$[*]' COLUMNS(value $operandType PATH '$')) AS t";
}
$unions = implode(' UNION ', $selects);
if ($expression->getOrdered()) {
$unions .= ' ORDER BY value';
}
return '(SELECT JSON_ARRAYAGG(value) AS value FROM (' . $unions . ') AS t)';
}
Signup or Login in order to comment.