-- FUNCTION: kolla.get_tabla_asociada_valor(character varying, character varying, character varying, character varying)

-- DROP FUNCTION kolla.get_tabla_asociada_valor(character varying, character varying, character varying, character varying);

CREATE OR REPLACE FUNCTION kolla.get_tabla_asociada_valor(
	tabla_nombre character varying,
	tabla_descripcion character varying,
	tabla_codigo character varying,
	codigo character varying)
    RETURNS character varying
    LANGUAGE 'plpgsql'

    COST 100
    VOLATILE 
    
AS $BODY$
DECLARE descripcion character varying;

BEGIN
  EXECUTE 'SELECT '|| tabla_descripcion ||' FROM ' || tabla_nombre || ' WHERE ' || tabla_codigo || '=' || codigo INTO descripcion;
  
  RETURN descripcion;
END;
$BODY$;