HAVING requires GROUP BY; count_subq is a correlated scalar subquery, not an aggregate, so PostgreSQL rejects it. WHERE works correctly and the integration tests used SQLite which is permissive about this rule. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>