The problem was fixed by initializing the array before giving it a value. Not surprising Postges isnt as popular as it should be. I was by luck that I found this out - the manual says nothing about init arrays. DECLARE id_var INTEGER[]; record_var RECORD; BEGIN id_var := '{}'; id_var[0] := 1; id_var[1] := 2; id_var[2] := 3; FOR record_var IN SELECT id FROM myTable WHERE id = ANY(id_var) LOOP RETURN NEXT record_var.id; END LOOP; RETURN; END;