30 lines
682 B
PL/PgSQL
30 lines
682 B
PL/PgSQL
CREATE OR REPLACE FUNCTION public.set_artist_name(in_url text) RETURNS integer
|
|
LANGUAGE plpgsql STRICT
|
|
AS $$
|
|
DECLARE
|
|
temp_artist_id integer;
|
|
temp_artist_name text;
|
|
BEGIN
|
|
temp_artist_name = get_artist_name(in_url);
|
|
temp_artist_name = convert_artist_name(temp_artist_name);
|
|
|
|
IF temp_artist_name IS NULL THEN
|
|
RETURN 1;
|
|
END IF;
|
|
|
|
PERFORM * FROM artist WHERE artist.name = temp_artist_name;
|
|
|
|
IF NOT FOUND THEN
|
|
INSERT INTO artist (name) VALUES (temp_artist_name);
|
|
END IF;
|
|
|
|
SELECT artist.id INTO temp_artist_id FROM artist
|
|
WHERE artist.name = temp_artist_name;
|
|
|
|
UPDATE artist_website SET artist_id = temp_artist_id
|
|
WHERE url = in_url;
|
|
|
|
RETURN 0;
|
|
END;
|
|
$$;
|