--
-- content_revision__get_content/1
--
create or replace function content_revision__get_content(
  get_content__revision_id integer
) returns text as $$

DECLARE
  v_storage_type                      cr_items.storage_type%TYPE;
  v_lob_id                            integer;
  v_data                              text;
BEGIN
       select i.storage_type, r.lob 
         into v_storage_type, v_lob_id
         from cr_items i, cr_revisions r
        where i.item_id = r.item_id 
          and r.revision_id = get_content__revision_id;
        
        if v_storage_type = 'lob' then
           return v_lob_id::text;
        else 
           return content
             from cr_revisions
            where revision_id = get_content__revision_id;
        end if;

END;
$$ language plpgsql;