from sqlalchemy.sql.expression import func
random_row = session.query(YourModel).order_by(func.random()).first()
this is equivalent to:
SELECT * FROM my_table ORDER BY RAND() LIMIT 1;
http://www.kavoir.com/2009/03/sql-randomly-shuffle-rows-or-records-reorder-them-in-a-random-order.html
I have
An ideal situation is to use predictable test interfaces. Hence ideally you
should have sequence of inserts and updates and selects at end of which you
should be able to verify that database logic is consistent with your
expectations.
But if random records query is a requirement, at outset you
Hi , I am not sure if this question will be considered sufficiently
python related. If its not than I am sorry I will take this somewhere
else
I am setting up some smoke tests for which I am fetching some records
from the db.
I am using sqlalchemy for this right now.
My real question when