Data update

This commit is contained in:
Ingy döt Net 2025-08-11 18:05:26 -07:00
parent 4d5544505c
commit 4924dd0264
3073 changed files with 55820 additions and 4408 deletions

View file

@ -0,0 +1,4 @@
set variable base= { 'name': 'Rocket Skates', 'price': 12.75, 'color':'yellow'}::JSON;
set variable update = { 'price': 15.25, 'color': 'red', 'year': 1974 }::JSON;
select json_merge_patch(getvariable('base'),getvariable('update')) as add;

View file

@ -0,0 +1,11 @@
create or replace function map_merge_patch(a,b) as (
with keys_t as (
select (map_keys(a) + map_keys(b)).list_distinct() as keys
),
values_t as (
select list_transform(keys, key -> coalesce(b[key][1],a[key][1])) as values
from keys_t)
select MAP(keys, values) from keys_t, values_t
);
select map_merge_patch( MAP([1,2],[1,2]), MAP([1,3],[10,30])) as add;

View file

@ -0,0 +1,11 @@
create or replace function struct_merge_patch(base, update) as (
<syntaxhighlight lang="sql">
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;