Skip to content

Instantly share code, notes, and snippets.

View KGOH's full-sized avatar
🙏
In academia, if it's good you publish it; In industry, you keep it secret

KgOfHedgehogs KGOH

🙏
In academia, if it's good you publish it; In industry, you keep it secret
View GitHub Profile
@Aitem
Aitem / jsonb_helper.sql
Last active December 16, 2022 18:46
PostreSQL JSONB helpers functions
-- 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;