python - Getting random row through SQLAlchemy -


how select a(or some) random row(s) table using sqlalchemy?

this database-specific issue.

i know postgresql , mysql have ability order random function, can use in sqlalchemy:

from  sqlalchemy.sql.expression import func, select  select.order_by(func.random()) # postgresql, sqlite  select.order_by(func.rand()) # mysql  select.order_by('dbms_random.value') # oracle 

next, need limit query number of records need (for example using .limit()).

bear in mind @ least in postgresql, selecting random record has severe perfomance issues; here article it.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -