You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way to get a random record or order randomly with Ormar ORM?
I couldn't find anything about that in the documentation, so I tried SQLalchemy's .order_by(func.rand()) and .order_by(func.random()). I also tried the Django ORM's way .order_by('?') in case, with no success.
So, for example the following raises an error:
from sqlalchemy.sql.expression import func
random_user = await Users.objects.order_by(func.rand()).limit(1).all()
Database is MySQL 8 - but question applies also for PostgreSQL 14
Python version is 3.9
Ormar version is 0.10.25
FastAPI version is 0.74.1
Pydantic version is 1.9.0
(Sorry I'm not sure if this is a documentation issue, a tech issue, a question, or a potential enhancement. Don't hesitate to change the label if needed.)
Activity
[-]Order by random[/-][+]Order by random raises error[/+][-]Order by random raises error[/-][+]Order by random[/+]PackingCenter commentedon Oct 4, 2023
so, is it possible to get N random rows with ormar in query?
(without getting all records and selecting N random from them)?
Phizilion commentedon Feb 22, 2024
Still need it