ALTER TABLE courses
ADD COLUMN IF NOT EXISTS physical_hole_count INTEGER;

UPDATE courses c
SET physical_hole_count = NULLIF(REGEXP_REPLACE(COALESCE(f.amenities->>'antall_hull', ''), '[^0-9]+', '', 'g'), '')::INTEGER
FROM facilities f
WHERE c.facility_id = f.id
  AND c.is_main_course = TRUE
  AND c.physical_hole_count IS NULL
  AND COALESCE(f.amenities->>'antall_hull', '') <> '';
