<div dir="ltr"><div><div>The duplication of the column in the select, though it appears to be a bug, shouldn&#39;t really be a problem as you are not adding any new entities that can be identified as &quot;quantity&quot;. <br><br>There is a problem in the general statement generated as, at least in the versions of SQL that I remember, it makes no sense to select distinct values of columns in a set grouped by another column. That is, in order to be meaningful in the traditional sense the only columns other than the group-by columns you can include would be sum(column), avg (column), etc. <br><br></div>Given the error that mysql provides it would appear that it is okay with this, so it has some other interpretation of the statement. I know that SQL Server and Sybase had something like this but it never made much sense to me and wasn&#39;t a part of the ANSI standard of the time. <br><br></div>The only way to correct this that I can think of is to remove all the columns from the result set and perhaps add the constant 1 or even sum(1) which would give you your result without the count (unless the -&gt;count gives you the number of distinct quantities in which case it should still work).<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On 10 October 2017 at 15:12, 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">Thank you, Gerhard!<br>
<br>
It was almost the first thing I tried, but it hadn&#39;t help. :-)<br>
<div class="HOEnZb"><div class="h5"><br>
On Tue, Oct 10, 2017 at 04:26:21PM +0200, Gerhard Jungwirth wrote:<br>
&gt; just guessing, did you try<br>
&gt;<br>
&gt; group_by =&gt; [ &#39;me.quantity&#39; ]<br>
&gt;<br>
&gt;<br>
&gt; On 2017-10-10 13:20, Vladimir Melnik wrote:<br>
&gt; &gt; Dear colleagues,<br>
&gt; &gt;<br>
&gt; &gt; Here&#39;s a little snippet of the code:<br>
&gt; &gt;     $resultset<br>
&gt; &gt;         -&gt;search(undef, { group_by =&gt; [ qw(quantity) ] })<br>
&gt; &gt;         -&gt;count;<br>
&gt; &gt;<br>
&gt; &gt; It produces the following exception:<br>
&gt; &gt; 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>
&gt; &gt;<br>
&gt; &gt; What is the best way to avoid that?<br>
&gt; &gt;<br>
&gt; &gt; Thanks in advance!<br>
&gt; &gt;<br>
&gt;<br>
&gt;<br>
&gt; ______________________________<wbr>_________________<br>
&gt; 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>
&gt; IRC: <a href="http://irc.perl.org#dbix-class" rel="noreferrer" target="_blank">irc.perl.org#dbix-class</a><br>
&gt; 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>
&gt; 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>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
V.Melnik<br>
</font></span><div class="HOEnZb"><div class="h5"><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>
</div></div></blockquote></div><br></div>