<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Wed May 22 11:05:43 UTC 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://www.doctrine-project.org/jira/si/jira.issueviews:issue-xml/DC-930/DC-930.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Doctrine Project</title>
    <link>http://www.doctrine-project.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>5.2.7</version>
        <build-number>850</build-number>
        <build-date>21-02-2013</build-date>
    </build-info>

<item>
            <title>[DC-930] Complex query with DISTINCT and LIMIT on pgsql causes a SQLSTATE exception - problem in doctrine_subquery_alias</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-930</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;There is a problem in the following code in Doctrine/Query.php (lines 1257-1279) inside the buildSqlQuery() method:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;            $subquery = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getLimitSubquery();

            &lt;span class=&quot;code-comment&quot;&gt;// what about composite keys?
&lt;/span&gt;            $idColumnName = $table-&amp;gt;getColumnName($table-&amp;gt;getIdentifier());

            &lt;span class=&quot;code-keyword&quot;&gt;switch&lt;/span&gt; (strtolower($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;getDriverName())) {
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;mysql&apos;:
[...]
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;pgsql&apos;:
                    $subqueryAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier(&apos;doctrine_subquery_alias&apos;);

                    &lt;span class=&quot;code-comment&quot;&gt;// pgsql needs special nested LIMIT subquery
&lt;/span&gt;                    $subquery = &apos;SELECT &apos; . $subqueryAlias . &apos;.&apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($idColumnName)
                            . &apos; FROM (&apos; . $subquery . &apos;) AS &apos; . $subqueryAlias;

                    &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
            }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The above code is executed when a query consist of DISTINCT and LIMIT clauses. The most common situation is using pager. &lt;br/&gt;
The problem is in the subquery variable. The $idColumnName variable often has value &quot;id&quot;. In such a situation in case of  $subquery consist of some JOINs and some tables have column named &quot;id&quot;, we have:&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-sql&quot;&gt;&lt;span class=&quot;code-keyword&quot;&gt;SELECT&lt;/span&gt; doctrine_subquery_alias.id &lt;span class=&quot;code-keyword&quot;&gt;FROM&lt;/span&gt; ((&lt;span class=&quot;code-keyword&quot;&gt;SELECT&lt;/span&gt; DISTINCT d1.id, d2.id &lt;span class=&quot;code-keyword&quot;&gt;FROM&lt;/span&gt; ...)) AS doctrine_subquery_alias
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;It, of course, causes the &quot;ambiguous column name&quot; pgsql exception.&lt;/p&gt;</description>
                <environment>pgsql</environment>
            <key id="12112">DC-930</key>
            <summary>Complex query with DISTINCT and LIMIT on pgsql causes a SQLSTATE exception - problem in doctrine_subquery_alias</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/open.png">Open</status>
                    <resolution id="-1">Unresolved</resolution>
                                <assignee username="guilhermeblanco">Guilherme Blanco</assignee>
                                <reporter username="j.debowczyk">Jacek D&#281;bowczyk</reporter>
                        <labels>
                    </labels>
                <created>Tue, 16 Nov 2010 09:54:02 +0000</created>
                <updated>Tue, 16 Nov 2010 09:54:02 +0000</updated>
                                    <version>1.2.2</version>
                                                <component>Query</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>