This must be faster:
create function fs_connect_by_great(integer) returns text as '
declare
id alias for $1;
pid integer;
title varchar;
folder varchar;
BEGIN
select parent_id, lower(file_title), folder_p INTO pid, title, folder from fs_files where id = file_id;
IF pid is null
THEN
return folder || ''/'' || title || ''/'' || fs_gen_key(id);
ELSE
return fs_connect_by_new(pid) || ''/'' || folder || ''/'' || title || ''/'' || fs_gen_key(id);
END IF;
END;
' language 'plpgsql';