Skip to content

Instantly share code, notes, and snippets.

@ArthurClune
Created July 5, 2012 22:20
Show Gist options
  • Save ArthurClune/3056834 to your computer and use it in GitHub Desktop.
Save ArthurClune/3056834 to your computer and use it in GitHub Desktop.
cursor.execute(
"""WITH tr AS (SELECT submitted_time AS tr_from, submitted_time - interval '%(hour)s hour' AS tr_until FROM attacks WHERE id = (SELECT max(id) FROM attacks))
SELECT ident_id, count(*) AS count, max(submitted_time) AS last, min(submitted_time) AS first, (SELECT tr_from FROM tr) AS tr_from, (SELECT tr_until FROM tr) AS tr_until, now()
FROM attacks, tr WHERE submitted_time > tr_until AND submitted_time <= tr_from AND ident_id IN (%(idents)s) GROUP BY ident_id ORDER BY count DESC""" ,
{"hours" : hours, "idents" : ','.join(map(str, ident_ids) )} )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment