daily pastebin goal
27%
SHARE
TWEET

Untitled

a guest Aug 18th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top