[Dbix-class] A count() after a grouping select() produces a "Duplicate column" error

Matthew Somerville matthew at mysociety.org
Tue Oct 10 21:26:44 GMT 2017


Hi,

With postgresql, I get:

§ DBIC_TRACE=1 DBIC_TRACE_PROFILE=console perl -e'use App::DB; print
App::DB->resultset("Problem")->search(undef, { group_by => [ qw(thing)
] })->count;'
SELECT COUNT( * )
  FROM (
    SELECT me.thing
      FROM problem me
    GROUP BY thing
   ) me
2

Which only fetches the required column to group, and only does it
once. Sorry, not sure if that's helpful, but it might require more
code than the little snippet to know what's going on.

ATB,
Matthew

On 10 October 2017 at 12:20, Vladimir Melnik <v.melnik at uplink.ua> wrote:
> Dear colleagues,
>
> Here's a little snippet of the code:
>         $resultset
>             ->search(undef, { group_by => [ qw(quantity) ] })
>             ->count;
>
> It produces the following exception:
> DBI Exception: DBD::mysql::st execute failed: Duplicate column name 'quantity' [for Statement "SELECT COUNT( * ) FROM (SELECT me.id, 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"] at /home/mmkeeper/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/DBIx/Class/Schema.pm line 1118.
>
> What is the best way to avoid that?
>
> Thanks in advance!
>
> --
> V.Melnik
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk



More information about the DBIx-Class mailing list