Index: database.sql ================================================================== --- database.sql +++ database.sql @@ -87,10 +87,26 @@ select id_tag from tag where usort(my_tag) = tag into tag_id; end if; return tag_id; end; $$; + +-- this function returns id of site array +create or replace function get_site(my_site text[]) returns integer + language plpgsql strict + as $$ +declare + site_id integer; +begin + select id_site from site where my_site = site into site_id; + if not found then + insert into site (site) values (my_site); + select id_site from site where my_site = site into site_id; + end if; + return site_id; +end; +$$; -- transforms domain into ordered array for indexing CREATE FUNCTION tripdomain(url text) RETURNS text[] LANGUAGE plpgsql IMMUTABLE STRICT AS $_$