Files
HDB/sql/set_folder_path.sql
2024-11-11 20:20:49 +01:00

39 lines
863 B
PL/PgSQL

CREATE OR REPLACE FUNCTION public.set_folder_path(in_url text) RETURNS integer
LANGUAGE plpgsql STRICT
AS $$
DECLARE
temp_folder_path text;
aw_artist_id integer;
aw_website_id integer;
artist_name text;
website_name text;
BEGIN
SELECT aw.artist_id INTO aw_artist_id FROM artist_website aw
WHERE aw.url = in_url;
IF aw_artist_id IS NULL THEN
RETURN 1;
END IF;
SELECT aw.website_id INTO aw_website_id FROM artist_website aw
WHERE aw.url = in_url;
IF aw_website_id IS NULL THEN
RETURN 1;
END IF;
SELECT artist.name INTO artist_name FROM artist
WHERE artist.id = aw_artist_id;
SELECT website.name INTO website_name FROM website
WHERE website.id = aw_website_id;
temp_folder_path = concat('Artists/', artist_name, '/', website_name);
UPDATE artist_website SET folder_path = temp_folder_path
WHERE url = in_url;
RETURN 0;
END;
$$;