create or replace function struct_merge_patch(base, update) as ( with cte as ( from (select unnest(update)) positional join (select COLUMNS(x -> x not in json_keys(update::JSON)) from (select unnest(base))) ) select cte from cte ); select struct_merge_patch( getvariable('base'), getvariable('update')) as merged;