Postgresql Plpgsql Loop Through Array Of Objects Js