[Dbix-class] Problems using a database function in the where clause

Moritz Onken onken at houseofdesign.de
Wed Jul 23 08:24:17 BST 2008


>>>>
>>>>
>>>> $rs->search({
>>>> -and =>
>>>> [
>>>>  {\"extract(year from age(NOW(),birthday))" => 22},
>>>>  {sex => "male"}
>>>> ]
>>>> });
>
> Have you tried the other way around?
>
> -and =>  [
>   { '' => \'extract(year from age(NOW(),birthday))'},
>   {sex => "male"}
> ]
>
> I couldn't understand what is the 22 doing there.

This query fetches all males who are 22 years old (postgresql syntax).

>
> But when you're using db-specifc stuff nobody';s written general  
> support
> for, a small chunk of raw SQL that solves the problem, encapsulated in
> a method on your resultset, is just fine.

The problem is that I create this query dynamically. It is much easier  
to push all
the restrictions in an array and pass that array to search() than  
creating the raw
sql from that array.

But If there is no way to solve this with dbic I'll just write plain  
sql.

thanks so far,



moritz



More information about the DBIx-Class mailing list