Question

Trying to convert this SQLite query

SELECT * FROM `terms` ORDER BY RANDOM() LIMIT 10

to work with a Sequel model. The closest I got:

Term.order(rand{}).limit(10)
Term.order('random ()').limit(10)

which translate into

<Sequel::SQLite::Dataset: "SELECT * FROM `terms` ORDER BY 0.6160215951854449 LIMIT 10">
<Sequel::SQLite::Dataset: "SELECT * FROM `terms` ORDER BY 'random ()' LIMIT 10">

but neither works. Is there a way to pass a SQLite- or other database-specific functions to Sequel's order()?

Was it helpful?

Solution

Using a Sequel.lit expression worked:

Term.order(Sequel.lit('RANDOM()')).limit(10)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top