`DISTINCT` cannot be used within `JSON_ARRAYAGG` in MySQL, so it was removed. Also, the PostgreSQL query was simplified and now generates JSONB columns, to be consistent with all the other tables.