[Dbix-class] Group By statistics columns

Trevor Phillips trevor.phillips at gmail.com
Mon Sep 21 07:42:55 GMT 2009


I have a table of logged data, which is too granular to browse row by
row. What I want to do is display a row per hour of data, and include
average/min/max for each field.

I can do this in SQL, using group by with a formatted timestamp field
to group per hour, along with AVG(), MIN(), MAX() on each field to get
the values I'm after. I can replicate the query in DBIx by defining
'select' and 'as'. However, I can't access these, I'm assuming because
I've given them names which don't match my DBIx::Class' defined column
names. A dump of the DBIx::Class shows the values in there as part of
_column_data.

So, for example, if my class has a column "foo", as does my DB table,
then what I want to access is foo_avg, foo_min and foo_max.

Is there an easy way to get a search resultset to auto-create the new columns?
Is there a better way to accomplish what I'm after?

I'm using DBIx::Class within Catalyst, with a MySQL DB, and Template
Toolkit for presentation.

Thanks.

-- 
Trevor Phillips  - http://dortamur.livejournal.com/
"On nights such as this, evil deeds are done. And good deeds, of
course. But mostly evil, on the whole."
      -- (Terry Pratchett, Wyrd Sisters)



More information about the DBIx-Class mailing list