Solutionunvalidated
Unnest the array once in a FROM LATERAL-style subquery and then count distinct on the unnested element grouped by id (e.g., `SELECT p.id, COUNT(DISTINCT mn) FROM permissions p, LATERAL unnest(p.serviceId) mn WHERE p.tenantId IN (...) GROUP BY p.id`).
4a02c3ed-cac4-4878-9915-6777beb65c70
Unnest the array once in a FROM LATERAL-style subquery and then count distinct on the unnested element grouped by id (e.g., SELECT p.id, COUNT(DISTINCT mn) FROM permissions p, LATERAL unnest(p.serviceId) mn WHERE p.tenantId IN (...) GROUP BY p.id).