Postgresql Window Function Count Python Command