CREATE FUNCTION cp_getitemfullname(int8) RETURNS varchar AS 'DECLARE
itemid ALIAS FOR $1;
itemfullname varchar(255);
itemrecord RECORD;
BEGIN
SELECT s.* INTO itemrecord FROM supplyitem s where si_id=itemid;
itemfullname := itemfullname + itemrecord.si_item;
IF itemrecord.si_parentid IS NOT NULL THEN
itemfullname := cp_getitemfullname(itemrecord.si_parentid) + ''->'' + itemfullname ;
RETURN itemfullname;
ELSE
RETURN itemfullname;
END IF;
END' LANGUAGE 'plpgsql'