This file contains hidden or 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
-- jsonb_select_keys take jsonb and keys and return jsonb | |
-- contains only given keys | |
create or REPLACE function jsonb_select_keys (resource jsonb, keys text[] ) returns jsonb | |
as $$ | |
select jsonb_object_agg(k, v) | |
from | |
(select unnest(keys) k ) k , | |
lateral (select resource->k.k as v) t; | |
$$ LANGUAGE SQL | |
IMMUTABLE; |