-- API for mail links create or replace function mail_link__new (integer,text) returns integer as ' declare new__mail_id alias for $1; new__url alias for $2; v_link_id mail_links.link_id%TYPE; begin select into v_link_id nextval(''mail_links_seq''); insert into mail_links (link_id, url) values (v_link_id, new__url); insert into mail_link_mail_map (mail_id, link_id) values (new__mail_id, v_link_id); return v_link_id; end;' language 'plpgsql'; create or replace function mail_link__delete (integer) returns integer as ' declare delete__link_id alias for $1; begin delete from mail_links where link_id = delete__link_id; return 0; end;' language 'plpgsql';