-- 316_eid_schedule_views_v_schedule_defer_pattern.sql — 305_eid_schedule_views.sql 분리본 (single-statement). asyncpg 러너가 prepared statement 로 처리해 multi-statement 거부 → 1 stmt/파일. 내용 불변.

CREATE OR REPLACE VIEW v_schedule_defer_pattern AS
SELECT eh.event_id,
       COUNT(*)::int       AS defer_reschedule_count,
       MAX(eh.changed_at)  AS last_changed_at,
       (COUNT(*) >= 3)     AS is_repeat_defer
FROM events_history eh
WHERE eh.change_kind IN ('defer','reschedule')
GROUP BY eh.event_id;
