return: text
lang: plpgsql
src: |
  DECLARE	
  	result TEXT;
  BEGIN
  	TRUNCATE activite.t_gme_c
  	;
  	INSERT INTO activite.t_gme_c(
  			    gme_id, gme_code, gme_texte, gme_section_id, gme_section_code, gme_section_texte, cm_id, 
  			    cm_code, cm_texte, cm_section_id, cm_section_code, cm_section_texte, 
  			    gn_id, gn_code, gn_texte, gn_section_id, gn_section_code, gn_section_texte, 
  			    rgme_id, rgme_code, rgme_texte, rgme_section_id, rgme_section_code, 
  			    rgme_section_texte)
  			SELECT
  				t_gme.oid,
  				t_gme.code,
  				t_gme.texte,
  				t_gme.section_id,
  				t_gme.section_code,
  				t_gme.section_texte,
  				t_cm.oid,
  				t_cm.code,
  				t_cm.texte,
  				t_cm.section_id,
  				t_cm.section_code,
  				t_cm.section_texte,
  				t_gn.oid,
  				t_gn.code,
  				t_gn.texte,
  				t_gn.section_id,
  				t_gn.section_code,
  				t_gn.section_texte,
  				t_rgme.oid,
  				t_rgme.code,
  				t_rgme.texte,
  				t_rgme.section_id,
  				t_rgme.section_code,
  				t_rgme.section_texte
  			FROM base.t_gme
  				JOIN base.t_cm ON t_cm.oid = t_gme.cm_id
  				JOIN base.t_gn ON t_gn.oid = t_gme.gn_id
  				JOIN base.t_rgme ON t_rgme.oid = t_gme.rgme_id
  	;
  		INSERT INTO activite.t_gme_c(
  			    gme_id, gme_code, gme_texte, 
  			    cm_id, cm_code, cm_texte, 
  			    gn_id, gn_code, gn_texte, 
  			    rgme_id, rgme_code, rgme_texte
  			    )
  			SELECT
  				oid,
  				code,
  				texte,
  				cm_id,
  				cm_code,
  				cm_texte,
  				gn_id,
  				gn_code,
  				gn_texte,
  				rgme_id,
  				rgme_code,
  				rgme_texte
  			FROM 
  			(
  				SELECT -9991 AS oid, '99_MCO' AS code, 'Hors SSR. MCO' AS texte, -9990 AS cm_id, '99' AS cm_code, 'Hors SSR' AS cm_texte, -9990 AS gn_id, 'ZZ' AS gn_code, 'Hors SSR' AS gn_texte, -9990 AS rgme_id, 'ZZ' AS rgme_code, 'Hors SSR' AS rgme_texte
  				UNION
  				SELECT -9990 AS oid, '99_ZZZ' AS code, 'Hors SSR. Divers' AS texte, -9990 AS cm_id, '99' AS cm_code, 'Hors SSR' AS cm_texte, -9990 AS gn_id, 'ZZ' AS gn_code, 'Hors SSR' AS gn_texte, -9990 AS rgme_id, 'ZZ' AS rgme_code, 'Hors SSR' AS rgme_texte
  				UNION
  				SELECT -9980 AS oid, '98_P' AS code, 'Champ SSR. Présents' AS texte, -9980 AS cm_id, '98' AS cm_code, 'Champ SSR. Non groupés' AS cm_texte, -9980 AS gn_id, 'ZY' AS gn_code, 'Champ SSR. Non groupés' AS gn_texte, -9980 AS rgme_id, 'ZY' AS rgme_code, 'Champ SSR. Non groupés' AS rgme_texte
  				UNION
  				SELECT -9981 AS oid, '98_NG' AS code, 'Champ SSR. Sortis non groupés' AS texte, -9980 AS cm_id, '98' AS cm_code, 'Champ SSR. Non groupés' AS cm_texte, -9980 AS gn_id, 'ZY' AS gn_code, 'Champ SSR. Non groupés' AS gn_texte, -9980 AS rgme_id, 'ZY' AS rgme_code, 'Champ SSR. Non groupés' AS rgme_texte
  				UNION
  				SELECT -9982 AS oid, '98_AX' AS code, 'Champ SSR. Sortis avant première expédition' AS texte, -9980 AS cm_id, '98' AS cm_code, 'Champ SSR. Non groupés' AS cm_texte, -9980 AS gn_id, 'ZY' AS gn_code, 'Champ SSR. Non groupés' AS gn_texte, -9980 AS rgme_id, 'ZY' AS rgme_code, 'Champ SSR. Non groupés' AS rgme_texte
  			
  			) subview
  			WHERE oid NOT IN (SELECT gme_id FROM activite.t_gme_c)
  	;
  
  	ANALYSE activite.t_gme_c
  	;
  
  				
  				
  	RETURN 'OK';
  END;