Postgres Row Number Partition Sql Function Coalesce