There is already a patch for that (ignore/respect nulls in lead/lag):https://commitfest.postgresql.org/action/patch_view?id=1096
--Vladimir