Group Rows by Name with Index Ranges in PostgreSQL