Skip to content

Combines two records into a single record by merging their fields.

merge(x: record, y: record) -> record

The merge function takes two records and returns a new record containing all fields from both records. If both records contain the same field, the value from the second record takes precedence.

The expression merge(x, y) has the same field precedence and null handling as {...x, ...y}.

from {x: {a: 1, b: 2}, y: {c: 3, d: 4}}
select result = merge(x, y)
{
result: {
a: 1,
b: 2,
c: 3,
d: 4
}
}

When fields exist in both records, the second record’s values take precedence:

from {
r1: {name: "Alice", age: 30},
r2: {name: "Bob", location: "NY"},
}
select result = merge(r1, r2)
{
result: {
name: "Bob",
age: 30,
location: "NY"
}
}

If either input is null, the input will be ignored.

from {x: {a: 1}, y: null}
select result = merge(x, y)
{
result: {
a: 1
}
}

Last updated: