Postgresql Window Function Count Python Array Sort Method