There was some discussion of doing this in a higher-order way, but for
right now, AVG is common enough that this patch should be integrated:

Index: ResultSetColumn.pm
===================================================================
--- ResultSetColumn.pm  (revision 9073)
+++ ResultSetColumn.pm  (working copy)
@@ -381,6 +381,48 @@

 sub sum_rs { return shift->func_rs('SUM') }

+
+=head2 avg
+
+=over 4
+
+=item Arguments: none
+
+=item Return Value: $average
+
+=back
+
+  my $avg_year = $year_col->avg();
+
+Wrapper for ->func. Returns the averge value of the column in the
+resultset (or C<undef> if there are none).
+
+=cut
+
+sub avg {
+  return shift->func('AVG');
+}
+
+=head2 avg_rs
+
+=over 4
+
+=item Arguments: none
+
+=item Return Value: $resultset
+
+=back
+
+  my $rs = $year_col->avg_rs();
+
+Wrapper for ->func_rs for function AVG().
+
+=cut
+
+sub min_rs { return shift->func_rs('AVG') }
+
+
+
 =head2 func

 =over 4

_______________________________________________
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/[email protected]

Reply via email to