[Dbix-class] More funky sql
Brandon Black
blblack at gmail.com
Mon Jan 16 23:11:49 CET 2006
Having been foiled earlier, I'm now looking through the rest of my
code for cases the branch might not handle well, or perhaps that I
just haven't discovered how to make the branch handle well, whatever
the case. This is the first one I've come across so far:
DISTINCT/COUNT stuff
attrs { distinct => 1 } seems to do "GROUP BY" rather than DISTINCT.
I think that works, and reasonably emulates what DISTINCT would have
done in normal use, but I can't be sure for all cases, I don't know.
The reasoning behind this is lost on me, but I'm sure there's a
reason. Of course "GROUP BY" doesn't work with count, so { distinct
=> 1 } doesn't either. Is there a construct that exists or that we
can make to handle the case:
SELECT COUNT(DISTINCT colname) FROM table [ WHERE ... ]
Perhaps:
->count( {}, { cols => [ 'colname' ], distinct => 1 } )
Where if @$cols == 1 && attrs{distinct}, issue the statement like the
SQL above, instead of bombing because distinct (as emulated by
group_by) and count cannot go together?
-- Brandon
More information about the Dbix-class
mailing list