chore(*.psql): update functions; add update_artist_key.psql for merging artists flow

This commit is contained in:
Cory Dransfeldt 2025-04-18 19:51:33 -07:00
parent 15982f220a
commit 678384d8d9
No known key found for this signature in database
8 changed files with 48 additions and 19 deletions

View file

@ -1,14 +1,21 @@
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
countries := array_cat(countries, string_to_array(result, delimiters[i]));
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
END;
$$ LANGUAGE plpgsql;