Last active
September 1, 2020 06:30
-
-
Save chapmanjacobd/983c28c04c5ee35d1b21eeffabf1c40d 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
do | |
$$ | |
declare | |
keys_u text; | |
begin | |
drop view if exists v_flat_u cascade; | |
select | |
string_agg(distinct format('data_json ->> %L as %I',rc, rc), ', ') data_json | |
into keys_u | |
from "dev", | |
jsonb_array_elements(users) ra, jsonb_strip_nulls(ra) rb, jsonb_object_keys(rb) as r(rc); | |
execute 'create view v_flat_u as select id, '||keys_u||' from "dev", jsonb_array_elements(users) as data_json'; | |
end; | |
$$ | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment