문제

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()?

도움이 되었습니까?

해결책

Using a Sequel.lit expression worked:

Term.order(Sequel.lit('RANDOM()')).limit(10)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top