When using a UUID as a primary key with PostgreSQL the grouping was defaulting to the row which caused incorrect results to be returned.