将默认值移到查询中,并在未选择日期时使用它们,这样可以吗?比如这样:
-- [params]
-- null date :start_date
-- null date :end_date
SELECT id as topic_id, created_at
FROM topics
WHERE created_at > COALESCE(:start_date, CAST(date_trunc('week', current_date) AS DATE))
AND created_at < COALESCE(:end_date, CAST(date_trunc('week', current_date) AS DATE)+4)