-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -- SIU-GUARANI 3 -- Version 3.0.0 -- Function: f_depurar_elementos -- -- Borra elementos que no tienen revisiones. Solo elementos de tipo Modulos que no sean compartibles. -- -- Recibe: -- f_depurar_elementos() -- -- Retorna: -- 1. OK -- -1. Error -- -- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -- DROP FUNCTION f_depurar_elementos(); CREATE OR REPLACE FUNCTION f_depurar_elementos() RETURNS TEXT AS $BODY$ DECLARE _rtn_mensaje text; BEGIN _rtn_mensaje := '1,OK'; -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -- Recupero las revisiones de los elementos que: -- a. Son modulos -- b. NO son compartibles. -- c. NO tienen revision -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ CREATE TEMP TABLE tmp_elementos (elemento integer); INSERT INTO tmp_elementos (elemento) SELECT sga_elementos.elemento FROM sga_elementos, sga_g3entidades_subtipos WHERE sga_elementos.entidad_subtipo = sga_g3entidades_subtipos.entidad_subtipo AND sga_elementos.compartible = 'N' -- No es compartible. AND sga_g3entidades_subtipos.entidad_tipo = 1 -- Modulos AND sga_elementos.entidad_subtipo <> 2 -- No sea Materia Genérica AND NOT EXISTS (SELECT elemento_revision FROM sga_elementos_revision WHERE sga_elementos_revision.elemento = sga_elementos.elemento); -- Borro atributos de los elementos sin revisiion. DELETE FROM sga_elementos_atrib WHERE sga_elementos_atrib.elemento IN (SELECT elemento FROM tmp_elementos); -- Borro elementos DELETE FROM sga_elementos WHERE sga_elementos.elemento IN (SELECT elemento FROM tmp_elementos); -- Borro tabla temporal DROP TABLE tmp_elementos; -- Salgo. _rtn_mensaje := '1,OK'; RETURN _rtn_mensaje; END; $BODY$ LANGUAGE 'plpgsql' VOLATILE; -- ++++++++++++++++++++++++++++++ Fin Function f_depurar_elementos() ++++++++++++++++ -- REVOKE EXECUTE ON FUNCTION f_depurar_elementos () FROM public; GRANT EXECUTE ON FUNCTION f_depurar_elementos () to public; /* select * from f_depurar_elementos() */