|| (arrays and objects)
On this page
Concatenates arrays or merges objects with the || operator.
Syntax
<left> || <right> [|| <next> ...]Arguments
| Argument | Type | Description |
|---|---|---|
<left> | array or object | First value. |
<right> | Same as <left> | Array to append or object to merge. |
<next> | Same as <left> | Optional additional values. |
Returns
Returns the same type as the inputs.
- Arrays preserve element order, duplicates, and NULL elements.
- Objects combine their top-level keys. For duplicate keys, the right-hand value replaces the left-hand value, including nested objects.
- If any input is NULL, returns NULL.
Examples
Combine event labels
Combine labels from an event and an investigation. Concatenation preserves both order and duplicates.
SELECT ['checkout', 'timeout'] || ['timeout', 'reviewed'] AS labelsThe labels value:
[
"checkout",
"timeout",
"timeout",
"reviewed"
]Use dedup on the combined array when the result should contain each label only once.
Apply event-specific attributes
Merge shared context with event-specific attributes. The right-hand object overrides a shared key.
SELECT
{'region': 'apac', 'channel': 'web'} ||
{'channel': 'mobile', 'campaign': 'spring'} AS attributesThe attributes value:
{
"campaign": "spring",
"channel": "mobile",
"region": "apac"
}The resulting channel is mobile; region is retained from the left-hand object.