Last active
March 29, 2021 12:54
-
-
Save lossendae/9568055671a2c1a0dccce6478e043b34 to your computer and use it in GitHub Desktop.
Various POSTGRESQL helpers
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
with | |
test as ( | |
select * | |
from ( | |
values | |
(123, '{"key_1": {"value_1": 1}}'::jsonb), | |
(123, '{"key_2": {"value_2": 2}}'::jsonb), | |
(123, '{"key_3": {"value_3": 3}}'::jsonb), | |
(456, '{"key_4": {"value_4": 4}}'::jsonb), | |
(456, '{"key_1": {"value_3": 4}}'::jsonb) | |
) | |
as t (id, values) | |
) | |
select id, jsonb_object_agg(t.k, t.v) | |
from test, jsonb_each(values::jsonb) as t(k,v) | |
group by id | |
order by id | |
; | |
+---+---------------------------------------------------------------------------+ | |
|id |jsonb_object_agg | | |
+---+---------------------------------------------------------------------------+ | |
|123|{"key_1": {"value_1": 1}, "key_2": {"value_2": 2}, "key_3": {"value_3": 3}}| | |
|456|{"key_1": {"value_3": 4}, "key_4": {"value_4": 4}} | | |
+---+---------------------------------------------------------------------------+ |
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
SELECT | |
proname, | |
proowner::regrole | |
FROM pg_proc | |
WHERE pronamespace::regnamespace::text = 'customer'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment