[Dbix-class] 2-argument SQL agregates
Matt S Trout
dbix-class at trout.me.uk
Tue Mar 28 18:19:14 CEST 2006
Doran L. Barton wrote:
> I need some help figuring out if it's possible, and if so how, to
> specify a 2-argument aggregate function for a search query using
> DBIx::Class.
>
> The examples in the docs say you can do this:
>
> my $rs = $schema->resultset(’Artist’)->search(
> {},
> {
> select => [ ’name’, { LENGTH => ’name’ } ],
> as => [qw/ name name_length /],
> }
> );
>
> This basically does:
>
> SELECT name, LENGTH('name') AS name_length FROM Artist
>
> I specifically need to use the TO_CHAR() function which takes a field
> name and a format string:
>
> SELECT foo, TO_CHAR('bar', 'Month DD YYYYY') FROM Artist
{ TO_CHAR => [ 'bar', 'Month DD YYYY' ] } ?
Always try the obvious thing first (this assumes you have quoting turned on.
if you don't, you probably want \"'Month DD YYYY'")
--
Matt S Trout Offering custom development, consultancy and support
Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
More information about the Dbix-class
mailing list