Created
April 5, 2016 12:59
-
-
Save kshvakov/b19a61a9febd979adc7f10c5a6fc0cd8 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 | |
_rawjson json; | |
_item record; | |
_id int; | |
_param text; | |
begin | |
for _rawjson in select * from json_array_elements('[{"id" : 42, "params" : ["bad", "sad"] }]'::json) loop | |
_item = (select j from json_to_record(_rawjson) AS j ( | |
id int, | |
params json | |
) | |
); | |
for _id, _param in select _item.id, _p from json_array_elements_text(_item.params) as _p loop | |
raise info 'id: %, param: %', _id, _param; | |
end loop; | |
end loop; | |
end $$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment