[Dbix-class] using distinct and literal SQL in select list
	does not work
    Marc Mims 
    marc at questright.com
       
    Tue Oct 14 20:09:52 BST 2008
    
    
  
* BUCHMULLER Norbert <norbi.lists at nix.hu> [081014 11:40]:
> On Tue, 14 Oct 2008 08:33:13 -0700 Marc Mims <marc at questright.com> wrote:
> Thanks, I know that, but that way I cannot use the column name in an
> 'order_by':
Are you sure you need the "as" alias for the order by?  The example you
gave to demonstrate the problem is perhaps too trivial.  Here's an
example that works just fine with an ORDER BY:
my $fn = \'length(me.name)';
$schema->resultset('Artist')->search(
    {
    },
    {
       select => [ $fn ],
       as     => [qw/one/],
       distinct => 1,
       order_by => [ $fn ],
    }
)->first;
Generated SQL:
SELECT length(me.name) FROM artist me GROUP BY length(me.name) ORDER BY
length(me.name)
	-Marc
    
    
More information about the DBIx-Class
mailing list