As a fun extra tip while Isaac takes a look at that, you can also use the user_id parameter to get a swish auto-complete parameter box. eg:
-- [params]
-- user_id :user
-- int :min_days = 10
WITH consecutive_visits AS (
SELECT user_id,
visited_at,
-- The value of s will be the same for each group of consecutive days
visited_at - (DENSE_RANK() OVER (PARTITION BY user_id ORDER BY visited_at))::int s
FROM user_visits
WHERE user_id = :user
)
SELECT
MIN(visited_at) period_start,
COUNT(*) AS consecutive_days,
MAX(visited_at) period_end
FROM consecutive_visits
GROUP BY user_id, s
HAVING COUNT(*) >= :min_days
ORDER BY period_start DESC