return: SETOF record
lang: plpgsql
parameters:
  p0:
    type: bigint
    name: i_indicateur_id
  p1:
    type: text
    name: i_table_name
  p2:
    type: text
    name: i_option
src: |
  DECLARE	
  	sqlcmd text;
  	
  	temp_cursor refcursor;
  	_oid integer;
  	_count integer;
  	_table_count integer;
  	_maxind integer;
  	_indicateur_name text;
  	
  	row  RECORD;
  BEGIN
  	
  	_maxind = 100;
  	_table_count = 0;
  	
  	OPEN temp_cursor FOR 
  	SELECT MAX(oid), SUM(CASE WHEN i_table_name = table_name THEN 1 ELSE 0 END)
  		FROM pmsi.t_indicateurs
  		WHERE oid IN (
  		SELECT base.cti_unnest(Array[oid, indicateur_associe_1_id, indicateur_associe_2_id, indicateur_associe_3_id, indicateur_associe_4_id, indicateur_associe_5_id])
  		FROM pmsi.t_indicateurs 
  		WHERE oid = i_indicateur_id);
  	
  	FETCH temp_cursor INTO _oid,_count;
  	WHILE FOUND LOOP
  		_maxind = _oid;
  		_table_count = _count;
  	FETCH temp_cursor INTO _oid, _count;
  	END LOOP;
  	CLOSE temp_cursor;
  	_indicateur_name = CASE i_table_name 
  				WHEN 'v_rss_1' THEN 'INDICATEURS_RSS'
  				WHEN 'v_rss_rum_1' THEN 'INDICATEURS_RUM'
  				WHEN 'v_rsf_detail_1' THEN 'INDICATEURS_PRESTA'
  				WHEN 'v_rsf_detail_6' THEN 'INDICATEURS_PRESTAH'
  				WHEN 'v_rss_lpp_1' THEN 'INDICATEURS_LPP'
  				WHEN 'v_rss_ucd_1' THEN 'INDICATEURS_UCD'
  				WHEN 'v_rss_actes_1' THEN 'INDICATEURS_ACTE'
  				WHEN 'v_rss_diagnostics_1' THEN 'INDICATEURS_DIAG'
  				WHEN 'v_rss_cancero_1' THEN 'INDICATEURS_CANCERO'
  				WHEN 'v_rss_src_1' THEN 'INDICATEURS_SRC'
  				WHEN 'v_rsf_detail_rum_1' THEN 'INDICATEURS_PRESTA_RUM'
  				WHEN 'v_rss_sae_1' THEN 'INDICATEURS_RSS_SAE'
  				ELSE 'INDICATEURS_OTHERS' END;
  	IF (_table_count = 0) THEN
  		FOR row IN SELECT _indicateur_name::text, ''::text
  		LOOP
  			RETURN NEXT row;
  		END LOOP;
  	END IF;
  	IF (_table_count > 0) THEN
  		FOR row IN 
  			SELECT 
  			_indicateur_name::text, base.cti_group_concat(CASE WHEN subview.oid IS NOT NULL THEN total_function || '(' || column_name || ')' ELSE 'NULL::numeric' END)
  			FROM generate_series(1, _maxind) 
  			LEFT JOIN 
  			(
  			SELECT *
  			FROM pmsi.t_indicateurs
  			WHERE oid IN (
  			SELECT base.cti_unnest(Array[oid, indicateur_associe_1_id, indicateur_associe_2_id, indicateur_associe_3_id, indicateur_associe_4_id, indicateur_associe_5_id])
  			FROM pmsi.t_indicateurs 
  			WHERE oid = i_indicateur_id)
  			) subview ON generate_series = subview.oid AND subview.table_name  = i_table_name
  			
  			
  			
  		LOOP
  			RETURN NEXT row;
  		END LOOP;
  	END IF;
  	
  	RETURN ;
  END;