From ea9fc2f81f7564637381e3466d4021a75822c907 Mon Sep 17 00:00:00 2001 From: Imdad Ahad Date: Wed, 5 Jul 2017 13:34:54 +0100 Subject: [PATCH] Use max in select --- app/commands.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/commands.py b/app/commands.py index 8f35e2fe8..ccad25334 100644 --- a/app/commands.py +++ b/app/commands.py @@ -126,7 +126,7 @@ class CustomDbScript(Command): """ MAX = 10000 - subq = "SELECT id FROM notifications WHERE cast (status as text) != notification_status".format(MAX) + subq = "SELECT id FROM notifications WHERE cast (status as text) != notification_status LIMIT {}".format(MAX) update = "UPDATE notifications SET notification_status = status WHERE id in ({})".format(subq) result = db.session.execute(subq).fetchall() @@ -136,7 +136,8 @@ class CustomDbScript(Command): db.session.commit() result = db.session.execute(subq).fetchall() - subq_hist = "SELECT id FROM notification_history WHERE cast (status as text) != notification_status".format(MAX) + subq_hist = "SELECT id FROM notification_history WHERE cast (status as text) != notification_status LIMIT {}" \ + .format(MAX) update = "UPDATE notification_history SET notification_status = status WHERE id in ({})".format(subq_hist) result = db.session.execute(subq_hist).fetchall()