def where(self, date, intervals):
"""
Generates a WHERE clause
Args:
date: the end date
intervals: intervals
Returns: a clause for filtering the from_obj to be between the date and
the greatest interval
"""
# upper bound
w = "{date_column} < '{date}'".format(
date_column=self.date_column, date=date)
# lower bound (if possible)
if 'all' not in intervals:
greatest = "greatest(%s)" % str.join(
",", ["interval '%s'" % i for i in intervals])
min_date = "'{date}'::date - {greatest}".format(date=date, greatest=greatest)
w += "AND {date_column} >= {min_date}".format(
date_column=self.date_column, min_date=min_date)
if self.input_min_date is not None:
w += "AND {date_column} >= '{bot}'::date".format(
date_column=self.date_column, bot=self.input_min_date)
return ex.text(w)
评论列表
文章目录