[Dbix-class] Searching N rows sorting randomly
Pedro Melo
melo at simplicidade.org
Sat Nov 28 18:18:36 GMT 2009
Hi,
On 2009/11/28, at 17:19, Alberto Simões wrote:
> SELECT word FROM words ORDER BY RANDOM() LIMIT 10;
>
> to get 10 random words from a database.
> I am trying to do the same query using DBIx::Class, but not sure what
> to set as order_by clause:
>
> my @words = $schema->resultset('Word')->search(undef,
> {rows =>
> $LIMIT,
> order_by
> => ...????
> columns =>
> ['word']});
Untested but try order_by => \'RANDOM()'
In other places, when you need to put direct SQL, you use a scalar
ref. Might work for order_by.
Bye,
More information about the DBIx-Class
mailing list