
create or replace function show_value(type smallint, id bigint) returns text as $$
declare tname text := (select dtname from datatypes as dt where dt.id = type);
begin
  return show_value(tname, id);
end;
$$ language plpgsql;

create or replace function show_value(tname text, id bigint) returns text as $$
begin
  case tname
    when 'node' then
      return (
        select ns.prefix || ':' || n.name 
          from nodes n
          join namespaces ns on ns.id = n.namespace
          where n.id = show_value.id
      );
    else return text(show_value.id);
  end case;
end;
$$ language plpgsql;
