I'm trying to create a set of functions that remove a group of related records from a set of tables. I've created a "master" function that identified the appropriate keys based on a user input, which then performs subordinate functions which delete the appropriate records from their associated tables. The function runs to completion without errors, but none of the deletes actually do anything. I've included RAISE NOTICE statement throughout the code and can see that the deletes are being executed without throwing any exceptions.

I've tried multiple different approaches to this including putting all the code in a single function with inline for..select..loop logic and nothing seems to work.

One final comment, if I run the "slave" functions individually, everything works correctly.

Following is the "master" function:

CREATE OR REPLACE FUNCTION delete_linkbases(p_linkbase_key numeric)
RETURNS void AS
$BODY$declare
cnt numeric;
w_linkbase_key linkbases.linkbase_key%type := 0;
w_linkbase_link_key linkbase_links.linkbase_link_key%type := 0;
begin
raise notice 'input param: %', p_linkbase_key;

for w_linkbase_key in select linkbase_key
from linkbases
where linkbase_key = p_linkbase_key loop

raise notice 'entering inner loop %', w_linkbase_key;
for w_linkbase_link_key in select linkbase_link_key
from linkbase_links
where linkbase_key = w_linkbase_key loop

raise notice 'running delete_linkbase_arcs %', w_linkbase_link_key;
perform delete_linkbase_arcs(w_linkbase_link_key);

raise notice 'running delete_linkbase_labels %', w_linkbase_link_key;
perform delete_linkbase_labels(w_linkbase_link_key);

raise notice 'running delete_linkbase_locators %', w_linkbase_link_key;
perform delete_linkbase_locators(w_linkbase_link_key);

end loop;
end loop;


Following is one of the slave functions:

CREATE OR REPLACE FUNCTION delete_linkbase_arcs(p_value numeric)
RETURNS void AS
$BODY$declare
cnt numeric := 0;
begin
-- raise notice 'entering delete_linkbase_arcs %', p_value;
select count(*) into cnt from linkbase_arcs where linkbase_link_key = p_value;
if cnt > 0 then
delete from only linkbase_arcs where linkbase_link_key = p_value;
raise notice 'linkbase_arcs rows: %', cnt;
else
raise notice 'linkbase_arcs empty';
end if;
end;$BODY$
LANGUAGE plpgsql VOLATILE
raise notice 'delete_linkbases done';
end;$BODY$
LANGUAGE plpgsql VOLATILE STRICT