return: text
lang: plpgsql
parameters:
  p0:
    type: text
    name: i_column_name
  p1:
    type: text
    name: i_table_name
  p2:
    type: integer
    name: i_array_index
  p3:
    type: bigint
    name: i_indicateur_id
  p4:
    type: bigint
    name: i_indicateur_associe_1_id
  p5:
    type: bigint
    name: i_indicateur_associe_2_id
  p6:
    type: bigint
    name: i_indicateur_associe_3_id
  p7:
    type: bigint
    name: i_indicateur_associe_4_id
  p8:
    type: bigint
    name: i_indicateur_associe_5_id
src: |
  DECLARE	
  	column_name text;
  	array_index text;
  BEGIN
  	array_index = '';
  	if i_array_index > 0 THEN
  		array_index = '[0000' || i_array_index || ']';
  	END IF;
  	if i_table_name <> '*CALC' THEN
  		column_name = 'SUM(indicateurs[000' || i_indicateur_id || ']' || array_index ||')';
  	ELSE
  		column_name = replace(i_column_name, '[1]', 'SUM(indicateurs[000' || i_indicateur_associe_1_id || ']' || array_index ||')');
  		column_name = replace(column_name, '[2]', 'SUM(indicateurs[000' || i_indicateur_associe_2_id || ']' || array_index ||')');
  		column_name = replace(column_name, '[3]', 'SUM(indicateurs[000' || i_indicateur_associe_3_id || ']' || array_index ||')');
  		column_name = replace(column_name, '[4]', 'SUM(indicateurs[000' || i_indicateur_associe_4_id || ']' || array_index ||')');
  		column_name = replace(column_name, '[5]', 'SUM(indicateurs[000' || i_indicateur_associe_5_id || ']' || array_index ||')');
  	END IF;
  		
  	RETURN column_name;
  END;