Select sqlalchemy mysql row package

I have a MySQL database with several thousand forum posts + text. I would like to capture them in batches, say 1000 at a time, and make stuff for them in python3.

My only post request looks like this:

pquery = session.query(Post).\ filter(Post.post_id.like(post_id)) 

How can I change this so that after post_id, it returns this post and 999 posts after it?

+5
source share
1 answer

Use limit and offset :

 pquery = session.query(Post).filter(Post.post_id.like(post_id)).limit(1000).offset(the_offset_val) 
+5
source

All Articles