<div dir="ltr">Greetings,<div><br></div><div>I&#39;m happy to take a stab at it!  If anyone sees anything I&#39;m missing please feel free to add your thoughts.<br><div><br></div><div>Looking at the generated SQL:</div><div><br></div><div><font face="monospace, monospace"><span style="font-size:12.8px">SELECT</span></font></div><div><font face="monospace, monospace"><span style="font-size:12.8px">  COUNT( * )</span></font></div><div><font face="monospace, monospace"><span style="font-size:12.8px">  FROM (</span></font></div><div><font face="monospace, monospace"><span style="font-size:12.8px">      SELECT</span></font></div><div><font face="monospace, monospace">        <a href="http://me.id/" rel="noreferrer" target="_blank" style="font-size:12.8px">me.id</a></font></div><div><font face="monospace, monospace"><span style="font-size:12.8px">        ,me.valid_from</span></font></div><div><font face="monospace, monospace"><span style="font-size:12.8px">        ,me.valid_till</span></font></div><div><font face="monospace, monospace"><span style="font-size:12.8px">        ,me.removed</span></font></div><div><font face="monospace, monospace"><span style="font-size:12.8px">        ,me.provisioning_agreement_id</span></font></div><div><font face="monospace, monospace"><span style="font-size:12.8px">        ,me.resource_piece_id</span></font></div><div><font face="monospace, monospace"><span style="font-size:12.8px">        ,me.service_type_id</span></font></div><div><font face="monospace, monospace"><span style="font-size:12.8px">        ,me.service_level_id</span></font></div><div><font face="monospace, monospace"><span style="font-size:12.8px"><b>        ,me.quantity</b></span></font></div><div><font face="monospace, monospace"><span style="font-size:12.8px"><b>        ,me.quantity</b></span></font></div><div><font face="monospace, monospace"><span style="font-size:12.8px">        FROM provisioning_obligation me</span></font></div><div><font face="monospace, monospace"><span style="font-size:12.8px">        GROUP BY quantity</span></font></div><div><font face="monospace, monospace"><span style="font-size:12.8px">  ) me</span></font><br></div><div><br></div><div>We can see that the quantity column is appearing twice (which is what is generating that Duplicate column name, because the derived table has the same column twice so it can&#39;t be &quot;fed into&quot; the SELECT COUNT(*) ).  Is it possible you copy pasted the quantity definition in the result source an extra time?  Alternatively, how are you generating the $resultset you are using, is it possible you are tacking on an extra quantity then, or are you querying the provisioning_obligation result source directly?</div><div><br></div><div>More importantly though, I&#39;m curious as to what information you are actually trying to get.  You want a distinct count of quantities from the provisioning_obligation table?  I&#39;m not sure the utility of that information, but a better way to answer that question would be to use a SELECT COUNT( DISTINCT quantity ), there is a great example in the docs at:</div><div><br></div><div><a href="http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/Manual/Cookbook.pod#SELECT_COUNT(DISTINCT_colname)">http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/Manual/Cookbook.pod#SELECT_COUNT(DISTINCT_colname)</a></div><div><br></div><div>Hopefully you find this helpful.</div><div><br></div><div>Best Regards,</div><div>Robert Stone</div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 10, 2017 at 6:20 AM, Vladimir Melnik <span dir="ltr">&lt;<a href="mailto:v.melnik@uplink.ua" target="_blank">v.melnik@uplink.ua</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear colleagues,<br>
<br>
Here&#39;s a little snippet of the code:<br>
        $resultset<br>
            -&gt;search(undef, { group_by =&gt; [ qw(quantity) ] })<br>
            -&gt;count;<br>
<br>
It produces the following exception:<br>
DBI Exception: DBD::mysql::st execute failed: Duplicate column name &#39;quantity&#39; [for Statement &quot;SELECT COUNT( * ) FROM (SELECT <a href="http://me.id" rel="noreferrer" target="_blank">me.id</a>, me.valid_from, me.valid_till, me.removed, me.provisioning_agreement_id, me.resource_piece_id, me.service_type_id, me.service_level_id, me.quantity, me.quantity FROM provisioning_obligation me GROUP BY quantity) me&quot;] at /home/mmkeeper/perl5/perlbrew/<wbr>perls/perl-5.24.0/lib/site_<wbr>perl/5.24.0/DBIx/Class/Schema.<wbr>pm line 1118.<br>
<br>
What is the best way to avoid that?<br>
<br>
Thanks in advance!<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
V.Melnik<br>
<br>
______________________________<wbr>_________________<br>
List: <a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class" rel="noreferrer" target="_blank">http://lists.scsys.co.uk/cgi-<wbr>bin/mailman/listinfo/dbix-<wbr>class</a><br>
IRC: <a href="http://irc.perl.org#dbix-class" rel="noreferrer" target="_blank">irc.perl.org#dbix-class</a><br>
SVN: <a href="http://dev.catalyst.perl.org/repos/bast/DBIx-Class/" rel="noreferrer" target="_blank">http://dev.catalyst.perl.org/<wbr>repos/bast/DBIx-Class/</a><br>
Searchable Archive: <a href="http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk" rel="noreferrer" target="_blank">http://www.grokbase.com/group/<wbr>dbix-class@lists.scsys.co.uk</a><br>
</font></span></blockquote></div><br></div>