Created
July 16, 2020 13:18
-
-
Save simon-engledew/8113f785d3bbfbfa4d3596d8e4ce5845 to your computer and use it in GitHub Desktop.
Postgres || for json instead of jsonb
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_merge_objects(a json, b json) RETURNS json | |
LANGUAGE SQL IMMUTABLE AS $$ | |
WITH combined AS ( | |
SELECT pair.key, pair.value FROM json_each(a) AS pair | |
UNION ALL | |
SELECT pair.key, pair.value FROM json_each(b) AS pair | |
) | |
SELECT json_object_agg(key, value) | |
FROM combined | |
$$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment