--
-- content_symlink__resolve/1
--
create or replace function content_symlink__resolve(
  integer
) returns int4 as $$

declare
  resolve__item_id                alias for $1;  
  v_target_id                     cr_items.item_id%TYPE;
begin

  select
    target_id into v_target_id
  from
    cr_symlinks
  where
    symlink_id = resolve__item_id;
  
  if NOT FOUND then
     return resolve__item_id;
  else
     return v_target_id;
  end if;

end;$$ language plpgsql;