modify sql functions

This commit is contained in:
2024-11-11 20:20:49 +01:00
parent e5a7906cdf
commit 9af2a9408c
12 changed files with 159 additions and 59 deletions

View File

@ -1,22 +1,28 @@
CREATE OR REPLACE PROCEDURE set_website_name(in_url text) AS $$
CREATE OR REPLACE FUNCTION public.set_website_name(in_url text) RETURNS integer
LANGUAGE plpgsql STRICT
AS $$
DECLARE
temp_website_id integer;
temp_website_name text;
temp_website website%ROWTYPE;
BEGIN
temp_website_name = get_website_name(in_url);
SELECT * INTO temp_website FROM website
WHERE website.name = temp_website_name;
IF temp_website_name IS NULL THEN
RETURN 1;
END IF;
PERFORM * FROM website WHERE website.name = temp_website_name;
IF NOT FOUND THEN
INSERT INTO website (name) VALUES (temp_website_name);
END IF;
SELECT website.id INTO temp_website_id FROM website
WHERE website.name = temp_website_name;
UPDATE artist_website SET website_id = temp_website_id
UPDATE artist_website SET website_id = temp_website_id
WHERE url = in_url;
RETURN 0;
END;
$$ LANGUAGE plpgsql;
$$;