Final Class Yiisoft\Db\Mssql\Builder\ArrayMergeBuilder
| Inheritance | Yiisoft\Db\Mssql\Builder\ArrayMergeBuilder » Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder |
|---|
Builds SQL expressions which merge arrays for {@see ArrayMerge} objects.
(SELECT '[' + STRING_AGG('"' + STRING_ESCAPE(value, 'json') + '"', ',') + ']' AS value FROM (
SELECT value FROM OPENJSON(operand1)
UNION
SELECT value FROM OPENJSON(operand2)
) AS t)
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| buildFromExpression() | Builds a SQL expression which merges arrays from the given {@see ArrayMerge} object. | Yiisoft\Db\Mssql\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
{
$selects = [];
foreach ($expression->getOperands() as $operand) {
$selects[] = 'SELECT value FROM OPENJSON(' . $this->buildOperand($operand, $params) . ')';
}
$unions = implode(' UNION ', $selects);
$orderBy = $expression->getOrdered() ? ' WITHIN GROUP (ORDER BY value)' : '';
return <<<SQL
(SELECT '[' + STRING_AGG('"' + STRING_ESCAPE(value, 'json') + '"', ',')$orderBy + ']' AS value FROM ($unions) AS t)
SQL;
}
Signup or Login in order to comment.