Guest User

Untitled

a guest
Aug 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. CREATE TABLE users (
  2. profile_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  3. last_updated TIMESTAMP DEFAULT now(),
  4. user_profile JSONB);
  5.  
  6. insert into users (user_profile) values ('{"first_name":"Patrick", "friends" : 888}');
  7. update users SET user_profile = json_set(user_profile,ARRAY['first_name'],'"heyyy"')::jsonb where user_profile->'first_name' @> to_json('Patrick');
  8.  
  9. // FULL default record update, deleting all other fields:
  10.  
  11. UPDATE users SET user_profile = '{"first_name": "Patrick", "friends": 0}' WHERE user_profile->'first_name' @> to_json('Ernie');
  12.  
  13. // Textual (macro-like) update of the json text
  14.  
  15. 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