Created
February 2, 2016 14:07
-
-
Save ianthrive/9369d58c435dca9342ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION json_diff(l JSONB, r JSONB) RETURNS JSONB LANGUAGE sql AS $$ | |
SELECT jsonb_object_agg(a.key, a.value) FROM | |
( SELECT key, value FROM jsonb_each(l) ) a LEFT OUTER JOIN | |
( SELECT key, value FROM jsonb_each(r) ) b ON a.key = b.key | |
WHERE a.value != b.value OR b.key IS NULL; | |
$$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment