added db functions for window functionality

I think the parameters for execute should be
cursor.execute (query, [TABLE_NAME, start_time, end_time, group_id])

http://initd.org/psycopg/docs/cursor.html