Guest User

Untitled

a guest
Mar 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. -- do this one-time
  2. CREATE OR REPLACE FUNCTION test_add_json(inp jsonb) RETURNS jsonb AS
  3. $$
  4. DECLARE
  5. response jsonb;
  6. BEGIN
  7. response := '{}'::jsonb;
  8. SELECT into response jsonb_insert(response, '{sum}', ((inp->>'a')::int + (inp->>'b')::int)::text::jsonb);
  9. RETURN response;
  10. END;
  11. $$
  12. LANGUAGE 'plpgsql';
  13.  
  14. -- this is how you'd call this function
  15. select test_add_json('{"a":1,"b":2}'::jsonb);
Add Comment
Please, Sign In to add comment