If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > Function performing function that contains delete logic fail w/o error

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-16-11, 15:08
nitewynd nitewynd is offline
Registered User
 
Join Date: Dec 2011
Posts: 1
Function performing function that contains delete logic fail w/o error

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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On