-- -- etp__get_title/2 -- create or replace function etp__get_title( integer, character varying ) returns varchar as $$ declare p_item_id alias for $1; p_revision_title alias for $2; v_item_id integer; v_title varchar; v_object_type varchar; begin if p_revision_title is not null then return p_revision_title; end if; select object_type from acs_objects into v_object_type where object_id = p_item_id; if v_object_type = 'content_folder' then select r.title into v_title from cr_items i, cr_revisions r where i.parent_id = p_item_id and i.name = 'index' and i.live_revision = r.revision_id; return v_title; end if; if v_object_type = 'content_extlink' then select label into v_title from cr_extlinks where extlink_id = p_item_id; return v_title; end if; if v_object_type = 'content_symlink' then select target_id into v_item_id from cr_symlinks where symlink_id = p_item_id; return etp__get_title(v_item_id, null); end if; if v_object_type = 'content_item' then select r.title into v_title from cr_items i, cr_revisions r where i.item_id = v_item_id and i.live_revision = r.revision_id; return v_title; end if; return null; end; $$ language plpgsql;