Quantcast
Viewing latest article 1
Browse Latest Browse All 3

Answer by Paarth for postgres jsonb_set multiple keys update

You can try this

Here we are using jsonb concatation operator || to Concatenate two jsonb objects

update table_name set data = (select val from (
(select 
CASE WHEN data ? key THEN jsonb_set(data, '{' || key || '}', quote_nullable(updated_value))
ELSE 
data || ('{' || quote_ident(key) || ':' || quote_ident(some_value) || '}')::jsonb
END val
 from json_each_text((select data::json from tbl))
CROSS JOIN tbl t
where key in ('city','phone','prefix') and number=1)) where number=1

Viewing latest article 1
Browse Latest Browse All 3

Trending Articles