Created
May 24, 2017 09:39
-
-
Save emiel/285178bb423d04b0f259c42931992d03 to your computer and use it in GitHub Desktop.
Delete multiple key/value pairs or string elements from left operand
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
-- | |
-- Coming in PostgreSQL 10 | |
-- https://www.postgresql.org/docs/10/static/functions-json.html | |
-- | |
create or replace function jsonb_delete_array(data jsonb, keys text[]) | |
returns jsonb immutable language sql | |
as $function$ | |
select coalesce(( | |
select jsonb_object_agg(key, value) | |
from jsonb_each(data) | |
where key <> all(keys) | |
), '{}'::jsonb) | |
$function$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment