Reputation: 11
I'm writing the API tests and when I use peewee function fn.Rand() I get this error:
cursor.execute(sql, params or ())
OperationalError: no such function: Rand
My code is:
query = Questions.select().order_by(fn.Rand()).limit(limit)
list = [ob.as_json() for ob in query]
Any ideia how to resolve?
Tks
Upvotes: 0
Views: 496
Reputation: 1663
# Pick 5 lucky winners:
LotteryNumber.select().order_by(fn.Random()).limit(5)
# Pick 5 lucky winners:
LotterNumber.select().order_by(fn.Rand()).limit(5)
According to the docs anyway....
Upvotes: 0
Reputation: 26245
Depending on the database, the function may be called "Random". Try changing your code to fn.Random()
.
Upvotes: 0