Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- do this one-time
- CREATE OR REPLACE FUNCTION test_add_json(inp jsonb) RETURNS jsonb AS
- $$
- DECLARE
- response jsonb;
- BEGIN
- response := '{}'::jsonb;
- SELECT into response jsonb_insert(response, '{sum}', ((inp->>'a')::int + (inp->>'b')::int)::text::jsonb);
- RETURN response;
- END;
- $$
- LANGUAGE 'plpgsql';
- -- this is how you'd call this function
- select test_add_json('{"a":1,"b":2}'::jsonb);
Add Comment
Please, Sign In to add comment