[英]limit number of rows peewee retrieve
我有以下python源文件可從MySQL數據庫檢索行。 問題在於訂戶表中要檢索的行太多。 如何限制要檢索和處理的小部分行等等?
class subinfo(peewee.Model):
sub_id = peewee.IntegerField()
active = peewee.BooleanField()
sub_type = peewee.IntegerField()
sub_cat = peewee.TextField()
class Meta:
database = locdb
class subscriber(peewee.Model):
sub_id = peewee.IntegerField(unique=True, primary_key=True)
sub_start = peewee.DateTimeField()
sub_end = peewee.DateTimeField()
ref_id = peewee.BigIntegerField()
class Meta:
database = locdb
for row in subscriber.select():
if(row.sub_start >= peewee.datetime.datetime.now()):
sub1, created = subinfo.get_or_create(sub_id=row.sub_id, active=True)
if(created == False & sub1.active == False):
q = subinfo.update(active=True).where(sub_id=row.sub_id)
q.execute()
else:
subinfo.get_or_create(sub_id=row.sub_id, active=False)
for row in subscriber.select()
對前100行執行此操作:
for row in subscriber.select().limit(100)
后100行:
for row in subscriber.select().limit(100).offset(100)
等等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.