Whose Error Is It?
Postgres printed this
ERROR: column "name" must appear in the GROUP BY clause or be used in an aggregate function
What it meansThe query selects the name column alongside an aggregate, but name is neither grouped nor aggregated, so its value would be ambiguous.
The first thing to checkAdd name to the GROUP BY clause, wrap it in an aggregate like max(name), or group by the primary key so Postgres can infer dependent columns.