Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE jsonbtest (data jsonb);
- INSERT INTO jsonbtest (data) VALUES ('{"city":"Mesa","county":"Maricopa","mayor":"John Smith"}');
- INSERT INTO jsonbtest (data) VALUES ('{"other city":"Mesa but with a longer name","county":"Maricopa","mayor":"John Smith Jr"}');
- SELECT (jsonb_each_text(data)).* FROM jsonbtest;
- key │ value
- ────────────┼────────────
- city │ Mesa
- mayor │ John Smith
- county │ Maricopa
- mayor │ John Smith
- county │ Maricopa
- other city │ Mesa
- (6 rows)
- SELECT key, max(char_length(value))
- FROM (SELECT (jsonb_each_text(data)).* FROM jsonbtest) t
- GROUP BY key;
- key │ max
- ────────────┼─────
- city │ 4
- other city │ 27
- county │ 8
- mayor │ 13
- (4 rows)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement