return: text
lang: plpgsql
src: |
  DECLARE	
    
    
    
    result TEXT;
  BEGIN
    -- Ménage pour tables partiellement générées
    RAISE NOTICE '%' , 'p_identites';
    DELETE FROM pmsi.p_identites WHERE rss_id NOT IN (SELECT oid FROM pmsi.p_rss);
    -- Ménage dans table des identites (bug #1688)
    DELETE FROM pmsi.p_identites
    USING pmsi.p_rss
    WHERE p_identites.rss_id = p_rss.oid AND
      p_identites.no_rss <> p_rss.no_rss;
      
    RAISE NOTICE '%' , 'p_rss_etat';
    DELETE FROM pmsi.p_rss_etat WHERE rss_id NOT IN (SELECT oid FROM pmsi.p_rss);
    
    RAISE NOTICE '%' , 'p_rss_rum';
    DELETE FROM pmsi.p_rss_rum WHERE rss_id NOT IN (SELECT oid FROM pmsi.p_rss);
    
    RAISE NOTICE '%' , 'p_rss_diagnostics';
    DELETE FROM pmsi.p_rss_diagnostics WHERE rss_id NOT IN (SELECT oid FROM pmsi.p_rss);
    
    RAISE NOTICE '%' , 'p_rss_actes';
    DELETE FROM pmsi.p_rss_actes WHERE rss_id NOT IN (SELECT oid FROM pmsi.p_rss);
    
    RAISE NOTICE '%' , 'p_rss_lpp';
    DELETE FROM pmsi.p_rss_lpp WHERE rss_id NOT IN (SELECT oid FROM pmsi.p_rss);
    
    RAISE NOTICE '%' , 'p_rss_ucd';
    DELETE FROM pmsi.p_rss_ucd WHERE rss_id NOT IN (SELECT oid FROM pmsi.p_rss);
    
    RAISE NOTICE '%' , 'p_rsf_total';
    DELETE FROM pmsi.p_rsf_total WHERE rss_id NOT IN (SELECT oid FROM pmsi.p_rss);
    
    RAISE NOTICE '%' , 'p_rsf_detail';
    DELETE FROM pmsi.p_rsf_detail WHERE rss_id NOT IN (SELECT oid FROM pmsi.p_rss);
  
    RAISE NOTICE '%' , 'p_rss_transferts';
    DELETE
      FROM pmsi.p_rss_transferts
      WHERE NOT EXISTS (
          SELECT 1
          FROM pmsi.p_rss
          WHERE p_rss.oid = p_rss_transferts.rss_id
      )
      ;

      
    RETURN 'OK';
  END;