I need help, trying to find why it goes to loop again when I run this function. It starts again after returning "OK" and it wont start with truncating the table.
CREATE OR REPLACE FUNCTION schema.table1()
RETURNS character varying AS
$BODY$
DECLARE var schema.table2;
DECLARE s_doc text;
BEGIN
perform ssv('HTTPS', 'on');
perform ssv('SERVER_NAME', 'www.url.domain');
perform ssv('DAD', 'website');
truncate schema.table3;
for var in (
select * from schema.table2
) loop
if var.content like '<?xml version="1.0" encoding="UTF-8"?>\n<XMLDoc format="XMLDOC-XML"%' then
insert into schema.table3 (id, doc)
values (var.id, var.content);
else
begin
s_doc:='<?xml version="1.0" encoding="UTF-8"?>\n'||schema.doc2XMLDOC(var, '1');
exception when others then
s_doc:=NULL;
end;
if s_doc is not null then
insert into schema.table3 (id, doc)
values (var.id, s_doc);
end if;
end if;
end loop;
return 'OK';
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION schema.export_doc()
OWNER TO sysadm;