[Dbix-class] Error when using distinct => 1 with select => ...

Peter Rabbitson rabbit+dbic at rabbit.us
Mon Jan 19 14:58:25 GMT 2015


On 01/12/2015 07:54 AM, Octavian Rasnita wrote:
> Hello,
>
> I tried to use the following select query, but it gives an error:
>
> use TB::Schema;
> $ENV{DBIC_TRACE}++;
>
> my $schema = TB::Schema->connect( "dbi:mysql:intranet", "root" );
>
> my $rs = $schema->resultset('Performance')->search( {}, {
>     select => [ { date => 'date_time' } ],
>     as => [ 'date' ],
>     distinct => 1,
> } );
>
> $rs->all;
>
> This gives the following result:
>
> SELECT DATE( date_time ) FROM performance me GROUP BY :
> DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::mysql::st
> execute failed: You have an error in your SQL syntax; check the manual
> that corresponds to your MySQL server version for the right syntax to
> use near '' at line 1 [for Statement "SELECT DATE( date_time ) FROM
> performance me GROUP BY "] at D:\test_dbic\test.pl line 18
>

There are two bugs in place here:

* DBIC does not check for an empty group_by properly (as seen in your case)
* distinct => 1 itself behaves correctly, but is not properly documented 
(argh!!!). The gist is "all columns are considered *except* for functions"

Both will be rectified in the next stable version.




More information about the DBIx-Class mailing list