Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE users (
- profile_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
- last_updated TIMESTAMP DEFAULT now(),
- user_profile JSONB);
- insert into users (user_profile) values ('{"first_name":"Patrick", "friends" : 888}');
- update users SET user_profile = json_set(user_profile,ARRAY['first_name'],'"heyyy"')::jsonb where user_profile->'first_name' @> to_json('Patrick');
- // FULL default record update, deleting all other fields:
- UPDATE users SET user_profile = '{"first_name": "Patrick", "friends": 0}' WHERE user_profile->'first_name' @> to_json('Ernie');
- // Textual (macro-like) update of the json text
- update users SET user_profile = replace(user_profile::TEXT,'"first_name":','"my-other-name":')::jsonb where user_profile->'first_name' @> to_json('Patrick')
Add Comment
Please, Sign In to add comment