src: |
  SELECT t_listes_tables.oid AS table_id,
      0 AS sequence,
      t_listes_tables.texte ||
          CASE
              WHEN count(DISTINCT t_classes.oid) > 0 THEN (' ('::text || count(DISTINCT t_classes.oid)::text) || ')'::text
              ELSE ''::text
          END AS texte,
      t_listes_tables.texte AS sort_1,
      '-1'::integer AS sort_2,
      0::bigint AS classe_id,
      '1'::text AS lvl,
      ''::text AS code,
      'rh'::text AS schema
     FROM rh.t_listes_tables
       LEFT JOIN rh.t_classes ON t_classes.table_id = t_listes_tables.oid
    WHERE t_listes_tables.code = ANY (ARRAY['PNI'::text, 'ANA'::text, 'SER'::text, 'QUA'::text, 'AGE'::text, 'CSC'::text, 'CEM'::text, 'ORC'::text, 'GCT'::text, 'MTD'::text, 'MTF'::text, 'MOA'::text, 'RUP'::text, 'SAP'::text, 'SAC'::text, 'SPE'::text, 'TCN'::text, 'THO'::text, 'CPO'::text, 'ANC'::text, 'SALXXX'::text, 'MVM'::text, 'ATC'::text, 'ATL'::text, 'ATN'::text, 'ATS'::text, 'FOR'::text, 'ETS'::text, 'CAE'::text, 'CAC'::text, 'CAS'::text, 'GCP'::text, 'COI'::text, 'FIL'::text, 'LEB'::text, 'UNF'::text, 'COT'::text, 'GRI'::text, 'GRG'::text, 'SAL'::text, 'STA'::text, 'CPT'::text, 'TTT'::text, 'NAT'::text, 'PSE'::text, 'PQU'::text, 'PAB'::text, 'POP'::text, 'PCH'::text])
    GROUP BY t_listes_tables.oid, t_listes_tables.texte
  UNION
   SELECT t_classes.table_id,
      t_classes.sequence,
      t_classes.texte,
      t_listes_tables.texte AS sort_1,
      t_classes.sequence AS sort_2,
      t_classes.oid AS classe_id,
      '2'::text AS lvl,
      t_classes.code,
      'rh'::text AS schema
     FROM rh.t_classes,
      rh.t_listes_tables
    WHERE t_classes.table_id = t_listes_tables.oid AND (t_listes_tables.code = ANY (ARRAY['PNI'::text, 'ANA'::text, 'SER'::text, 'QUA'::text, 'AGE'::text, 'CSC'::text, 'CEM'::text, 'ORC'::text, 'GCT'::text, 'MTD'::text, 'MTF'::text, 'MOA'::text, 'RUP'::text, 'SAP'::text, 'SAC'::text, 'SPE'::text, 'TCN'::text, 'THO'::text, 'CPO'::text, 'ANC'::text, 'SALXXX'::text, 'MVM'::text, 'ATC'::text, 'ATL'::text, 'ATN'::text, 'ATS'::text, 'FOR'::text, 'ETS'::text, 'CAE'::text, 'CAC'::text, 'CAS'::text, 'GCP'::text, 'COI'::text, 'FIL'::text, 'LEB'::text, 'UNF'::text, 'COT'::text, 'GRI'::text, 'GRG'::text, 'SAL'::text, 'STA'::text, 'CPT'::text, 'TTT'::text, 'NAT'::text, 'PSE'::text, 'PQU'::text, 'PAB'::text, 'POP'::text, 'PCH'::text])) AND t_classes.sequence >= 1
  UNION
   SELECT t_listes_tables.oid AS table_id,
      '-1'::integer AS sequence,
      'Nouvelle classe'::text AS texte,
      t_listes_tables.texte AS sort_1,
      0 AS sort_2,
      '-1'::integer::bigint AS classe_id,
      '2'::text AS lvl,
      ''::text AS code,
      'rh'::text AS schema
     FROM rh.t_listes_tables
    WHERE t_listes_tables.code = ANY (ARRAY['PNI'::text, 'ANA'::text, 'SER'::text, 'QUA'::text, 'AGE'::text, 'CSC'::text, 'CEM'::text, 'ORC'::text, 'GCT'::text, 'MTD'::text, 'MTF'::text, 'MOA'::text, 'RUP'::text, 'SAP'::text, 'SAC'::text, 'SPE'::text, 'TCN'::text, 'THO'::text, 'CPO'::text, 'ANC'::text, 'SALXXX'::text, 'MVM'::text, 'ATC'::text, 'ATL'::text, 'ATN'::text, 'ATS'::text, 'FOR'::text, 'ETS'::text, 'CAE'::text, 'CAC'::text, 'CAS'::text, 'GCP'::text, 'COI'::text, 'FIL'::text, 'LEB'::text, 'UNF'::text, 'COT'::text, 'GRI'::text, 'GRG'::text, 'SAL'::text, 'STA'::text, 'CPT'::text, 'TTT'::text, 'NAT'::text, 'PSE'::text, 'PQU'::text, 'PAB'::text, 'POP'::text, 'PCH'::text])
  UNION
   SELECT t_listes_tables.oid AS table_id,
      0 AS sequence,
      t_listes_tables.texte,
      t_listes_tables.texte AS sort_1,
      '-1'::integer AS sort_2,
      0::bigint AS classe_id,
      '1'::text AS lvl,
      ''::text AS code,
      'base'::text AS schema
     FROM base.t_listes_tables
    WHERE t_listes_tables.code = ANY (ARRAY['POLE'::text])
  UNION
   SELECT t_classes.table_id,
      t_classes.sequence,
      t_classes.texte,
      t_listes_tables.texte AS sort_1,
      t_classes.sequence AS sort_2,
      t_classes.oid AS classe_id,
      '2'::text AS lvl,
      t_classes.code,
      'base'::text AS schema
     FROM base.t_classes,
      base.t_listes_tables
    WHERE t_classes.table_id = t_listes_tables.oid AND (t_listes_tables.code = ANY (ARRAY['POLE'::text])) AND t_classes.sequence >= 1
  UNION
   SELECT t_listes_tables.oid AS table_id,
      '-1'::integer AS sequence,
      'Nouvelle classe'::text AS texte,
      t_listes_tables.texte AS sort_1,
      0 AS sort_2,
      '-1'::integer::bigint AS classe_id,
      '2'::text AS lvl,
      ''::text AS code,
      'base'::text AS schema
     FROM base.t_listes_tables
    WHERE t_listes_tables.code = ANY (ARRAY['POLE'::text])
    ORDER BY 4, 5;