So I have a table with a datestamp and two fields that I want to make sure that they are unique in the last month.
table.id
table.datestamp
table.field1
table.field2
There should be no duplicate record with the same field1 + 2 compound value in the last month.
The steps in my head are:
- Group by the two fields
- Look back over the last month's data to make sure this unique grouping doesn't occur.
I've got this far, but I don't think this works:
result = session.query(table).group_by(\
table.field1,
table.field2,
func.month(table.timestamp))
But I'm unsure how to do this in sqlalchemy. Could someone advise me?
Thanks very much!