title: Doctrine SQL query: works on MySQL, on PostgreSQL won't
body: <p>This is a query automatically generated by Taggable extension for Doctrine ORM.</p>
  
  <pre><code>SELECT t.id AS t__id, t.name AS t__name, COUNT(DISTINCT i.id) AS i__0,
     (COUNT(DISTINCT i.id)) AS i__1
  FROM taggable_tag t
  LEFT JOIN cms__model__image_taggable_tag c ON (t.id = c.tag_id)
  LEFT JOIN image i ON i.id = c.id
  WHERE t.id IN
      (SELECT doctrine_subquery_alias.id
       FROM
         (SELECT DISTINCT t2.id, (COUNT(DISTINCT i2.id)) AS i2__1
          FROM taggable_tag t2
          LEFT JOIN cms__model__image_taggable_tag c2 ON (t2.id = c2.tag_id)
          LEFT JOIN image i2 ON i2.id = c2.id
          GROUP BY t2.id HAVING i2__1 &gt; 0
          ORDER BY i2__1 DESC LIMIT 10) AS doctrine_subquery_alias)
  GROUP BY t.id HAVING i__1 &gt; 0
  ORDER BY i__1 DESC
  </code></pre>
  
  <p>It works when using MySql, but won't work with PostgreSql.</p>
  
  <p>I get: <code>column i2__1 not found</code> or <code>column i__2 not found</code>.</p>
  
  <p>Are aliases disallowed when using COUNT(DISTINCT)?<br>
  How this query should look like to work on PostgreSql?</p>