Skip to content

Instantly share code, notes, and snippets.

@kshvakov
Created April 5, 2016 12:59
Show Gist options
  • Save kshvakov/b19a61a9febd979adc7f10c5a6fc0cd8 to your computer and use it in GitHub Desktop.
Save kshvakov/b19a61a9febd979adc7f10c5a6fc0cd8 to your computer and use it in GitHub Desktop.
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