CREATE OR REPLACE FUNCTION normalize_country_field(countryField TEXT)
RETURNS TEXT AS $$
DECLARE
  delimiters TEXT[] := ARRAY[',', '/', '&', 'and'];
  countries TEXT[];
  temp TEXT[];
  result TEXT := '';
  i INTEGER;
BEGIN
  countries := string_to_array(countryField, ',');
  FOR i IN 1..array_length(delimiters, 1) LOOP
    temp := ARRAY[]::TEXT[];
    FOREACH result IN ARRAY countries LOOP
      temp := array_cat(temp, string_to_array(result, delimiters[i]));
    END LOOP;
    countries := temp;
  END LOOP;
  result := array_to_string(countries, ' ');
  RETURN trim(result);
END;
$$ LANGUAGE plpgsql;
