phildeman has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone know how to query a database by randomly selecting limited rows. I know how to do it in SQL. I want to convert this:
SELECT column FROM table ORDER BY RAND() LIMIT 20;
to this:
my @tickers = $schema->resultset( 'TickerTable' )->search( {}, { order_by => Random(), + columns => ['DisplayName'], + rows => 20 + });

Replies are listed 'Best First'.
Re: How to select limited rows randomly in DBIx::Class?
by Your Mother (Archbishop) on Jan 28, 2015 at 23:25 UTC

    :P

    my @tickers = $schema ->resultset('TickerTable') ->search({}, { order_by => \"RAND()", columns => ['DisplayName'], rows => 20 });

    String refs (\"") are used as literals to the DB in this case.

Re: How to select limited rows randomly in DBIx::Class?
by duelafn (Parson) on Jan 29, 2015 at 02:20 UTC

    See also Helper::ResultSet::Random which would (I believe) give the lovely syntax:

    my @tickers = $schema->resultset( 'TickerTable' )->rand(20)->search({} +, { columns => ['DisplayName'] });

    Good Day,
        Dean

Re: How to select limited rows randomly in DBIx::Class?
by erix (Prior) on Jan 28, 2015 at 22:12 UTC

    Can you say what database (DBMS) this should work in?