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

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

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

unit testing - How to mock PreferenceManager in Android? -