- (SELECT ipaddress, sum(case when endtime is null then 1 else 1+1.5*date_part('epoch',endtime-starttime) end) as count FROM new_query_log
+ (SELECT ipaddress, sum(case when endtime is null then 1 else 1+1.5*date_part('epoch',endtime-starttime) end) as count, substring(max(useragent) from 1 for 30) as ua FROM new_query_log
WHERE starttime > now() - interval '1 hour' GROUP BY ipaddress) as i
WHERE count > %s)
UNION
WHERE starttime > now() - interval '1 hour' GROUP BY ipaddress) as i
WHERE count > %s)
UNION
- (SELECT ipaddress, count * 3 FROM
- (SELECT ipaddress, sum(case when endtime is null then 1 else 1+1.5*date_part('epoch',endtime-starttime) end) as count FROM new_query_log
+ (SELECT ipaddress, count * 3, ua FROM
+ (SELECT ipaddress, sum(case when endtime is null then 1 else 1+1.5*date_part('epoch',endtime-starttime) end) as count, substring(max(useragent) from 1 for 30) as ua FROM new_query_log
WHERE starttime > now() - interval '10 min' GROUP BY ipaddress) as i
WHERE count > %s)) as o
GROUP BY ipaddress
WHERE starttime > now() - interval '10 min' GROUP BY ipaddress) as i