· 7 years ago · Feb 10, 2019, 08:30 AM
1drop function if exists mcom.fn_referentes_info(varchar, varchar, varchar, varchar, varchar, varchar);
2create function mcom.fn_referentes_info(
3 host varchar,
4 puerto varchar,
5 usuario varchar,
6 contrasenia varchar,
7 bd varchar,
8 codigoReferente varchar)
9 returns TABLE(
10 perfil_competencia text,
11 ambito_profesional text,
12 sector_productivo text,
13 ocupacion text,
14 tipo text)
15language plpgsql
16as $$
17BEGIN
18
19 RETURN QUERY select *
20 from dblink(
21 'host=' || ' ' || host || ' ' ||
22 'port=' || ' ' || puerto || ' ' ||
23 'user=' || ' ' || usuario || ' ' ||
24 'password=' || ' ' || contrasenia || ' ' ||
25 'dbname=' || ' ' || bd,
26 '
27 select perfil, '''' :: text, '''' :: text, '''' :: text, ''norma'' :: text from public.normas_normatecnica where codigo = '
28 ||
29 '''' || codigoReferente || '''')
30 as (campo1 text, campo2 text, campo3 text, campo4 text, campo5 text);
31
32 IF NOT FOUND
33 THEN
34
35 RETURN QUERY select *
36 from dblink(
37 'host=' || ' ' || host || ' ' ||
38 'port=' || ' ' || puerto || ' ' ||
39 'user=' || ' ' || usuario || ' ' ||
40 'password=' || ' ' || contrasenia || ' ' ||
41 'dbname=' || ' ' || bd,
42 '
43 select
44 competencia,
45 ambito,
46 sector_pro,
47 ocupacion,
48 ''cualificacion'' :: text
49 from public.cualificacion_cualificacionprofesional
50 where codigo = ' || '''' || codigoReferente || '''')
51 as (campo1 text, campo2 text, campo3 text, campo4 text, campo5 text);
52 end if;
53END;
54$$;
55
56comment on function mcom.fn_referentes_info(varchar, varchar, varchar, varchar, varchar, varchar)
57is 'Obtiene información adicional del referente alojado en Portaltec, dependiendo del código del referente, hace uso de dblink();';