src: |
  SELECT p_mat2a_data.oid,
      p_mat2a_data.mat2a_import_id,
      p_mat2a_data.file_code,
      p_mat2a_data.table_sequence,
      p_mat2a_data.row_sequence,
      p_mat2a_data.line_type,
      p_mat2a_data.data_mat2a,
      p_mat2a_data.data_cti,
      ARRAY[
          CASE
              WHEN p_mat2a_data.data_cti[1] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[1]) - base.cti_to_number(p_mat2a_data.data_mat2a[1])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[2] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[2]) - base.cti_to_number(p_mat2a_data.data_mat2a[2])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[3] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[3]) - base.cti_to_number(p_mat2a_data.data_mat2a[3])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[4] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[4]) - base.cti_to_number(p_mat2a_data.data_mat2a[4])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[5] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[5]) - base.cti_to_number(p_mat2a_data.data_mat2a[5])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[6] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[6]) - base.cti_to_number(p_mat2a_data.data_mat2a[6])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[7] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[7]) - base.cti_to_number(p_mat2a_data.data_mat2a[7])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[8] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[8]) - base.cti_to_number(p_mat2a_data.data_mat2a[8])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[9] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[9]) - base.cti_to_number(p_mat2a_data.data_mat2a[9])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[10] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[10]) - base.cti_to_number(p_mat2a_data.data_mat2a[10])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[11] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[11]) - base.cti_to_number(p_mat2a_data.data_mat2a[11])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[12] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[12]) - base.cti_to_number(p_mat2a_data.data_mat2a[12])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[13] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[13]) - base.cti_to_number(p_mat2a_data.data_mat2a[13])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[14] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[14]) - base.cti_to_number(p_mat2a_data.data_mat2a[14])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[15] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[15]) - base.cti_to_number(p_mat2a_data.data_mat2a[15])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[16] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[16]) - base.cti_to_number(p_mat2a_data.data_mat2a[16])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[17] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[17]) - base.cti_to_number(p_mat2a_data.data_mat2a[17])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[18] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[18]) - base.cti_to_number(p_mat2a_data.data_mat2a[18])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[19] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[19]) - base.cti_to_number(p_mat2a_data.data_mat2a[19])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[20] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[20]) - base.cti_to_number(p_mat2a_data.data_mat2a[20])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[21] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[21]) - base.cti_to_number(p_mat2a_data.data_mat2a[21])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[22] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[22]) - base.cti_to_number(p_mat2a_data.data_mat2a[22])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[23] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[23]) - base.cti_to_number(p_mat2a_data.data_mat2a[23])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[24] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[24]) - base.cti_to_number(p_mat2a_data.data_mat2a[24])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[25] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[25]) - base.cti_to_number(p_mat2a_data.data_mat2a[25])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[26] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[26]) - base.cti_to_number(p_mat2a_data.data_mat2a[26])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[27] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[27]) - base.cti_to_number(p_mat2a_data.data_mat2a[27])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[28] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[28]) - base.cti_to_number(p_mat2a_data.data_mat2a[28])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[29] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[29]) - base.cti_to_number(p_mat2a_data.data_mat2a[29])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END,
          CASE
              WHEN p_mat2a_data.data_cti[30] IS NULL THEN ''::text
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[30]) - base.cti_to_number(p_mat2a_data.data_mat2a[30])) >= 1::numeric THEN '1'::text
              ELSE '0'::text
          END] AS data_err,
          CASE
              WHEN p_mat2a_data.data_cti[1] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[1]) - base.cti_to_number(p_mat2a_data.data_mat2a[1])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[2] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[2]) - base.cti_to_number(p_mat2a_data.data_mat2a[2])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[3] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[3]) - base.cti_to_number(p_mat2a_data.data_mat2a[3])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[4] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[4]) - base.cti_to_number(p_mat2a_data.data_mat2a[4])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[5] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[5]) - base.cti_to_number(p_mat2a_data.data_mat2a[5])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[6] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[6]) - base.cti_to_number(p_mat2a_data.data_mat2a[6])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[7] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[7]) - base.cti_to_number(p_mat2a_data.data_mat2a[7])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[8] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[8]) - base.cti_to_number(p_mat2a_data.data_mat2a[8])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[9] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[9]) - base.cti_to_number(p_mat2a_data.data_mat2a[9])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[10] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[10]) - base.cti_to_number(p_mat2a_data.data_mat2a[10])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[11] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[11]) - base.cti_to_number(p_mat2a_data.data_mat2a[11])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[12] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[12]) - base.cti_to_number(p_mat2a_data.data_mat2a[12])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[13] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[13]) - base.cti_to_number(p_mat2a_data.data_mat2a[13])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[14] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[14]) - base.cti_to_number(p_mat2a_data.data_mat2a[14])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[15] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[15]) - base.cti_to_number(p_mat2a_data.data_mat2a[15])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[16] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[16]) - base.cti_to_number(p_mat2a_data.data_mat2a[16])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[17] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[17]) - base.cti_to_number(p_mat2a_data.data_mat2a[17])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[18] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[18]) - base.cti_to_number(p_mat2a_data.data_mat2a[18])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[19] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[19]) - base.cti_to_number(p_mat2a_data.data_mat2a[19])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[20] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[20]) - base.cti_to_number(p_mat2a_data.data_mat2a[20])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[21] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[21]) - base.cti_to_number(p_mat2a_data.data_mat2a[21])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[22] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[22]) - base.cti_to_number(p_mat2a_data.data_mat2a[22])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[23] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[23]) - base.cti_to_number(p_mat2a_data.data_mat2a[23])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[24] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[24]) - base.cti_to_number(p_mat2a_data.data_mat2a[24])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[25] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[25]) - base.cti_to_number(p_mat2a_data.data_mat2a[25])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[26] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[26]) - base.cti_to_number(p_mat2a_data.data_mat2a[26])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[27] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[27]) - base.cti_to_number(p_mat2a_data.data_mat2a[27])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[28] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[28]) - base.cti_to_number(p_mat2a_data.data_mat2a[28])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[29] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[29]) - base.cti_to_number(p_mat2a_data.data_mat2a[29])) >= 1::numeric THEN 1
              ELSE 0
          END +
          CASE
              WHEN p_mat2a_data.data_cti[30] IS NULL THEN 0
              WHEN abs(base.cti_to_number(p_mat2a_data.data_cti[30]) - base.cti_to_number(p_mat2a_data.data_mat2a[30])) >= 1::numeric THEN 1
              ELSE 0
          END AS nb_data_err
     FROM pmsi.p_mat2a_data
    WHERE p_mat2a_data.line_type = ANY (ARRAY['D'::text, 'F'::text]);