explain verbose
WITH removed AS (
  DELETE FROM match m
  WHERE
    NOT EXISTS (
        SELECT 1
        FROM build.household h
        WHERE h.household_id = m.household_id
    ) OR (
      m.property_id IS NOT NULL AND
      NOT EXISTS (
          SELECT 1
          FROM build.property p
          WHERE p.household_id = m.household_id AND p.property_id = m.property_id
      )
    )
  RETURNING *
)
INSERT INTO orphaned_matches (household_id, account_id, candidate_id, matched_at, full_name, first_name, last_name, match_reason, property_id, owner_id)
  SELECT
    removed.household_id,
    removed.account_id,
    removed.candidate_id,
    removed.created_at,
    removed.full_name,
    removed.first_name,
    removed.last_name,
    removed.match_reason,
    removed.property_id,
    removed.owner_id
  FROM removed;
