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) AS sort_2,
      0::bigint AS classe_id,
      '1'::text AS lvl,
      ''::text AS code,
      'compta'::text AS schema
     FROM compta.t_listes_tables
       LEFT JOIN compta.t_classes ON t_classes.table_id = t_listes_tables.oid
    WHERE t_listes_tables.code = ANY (ARRAY['CPT'::text, 'JRN'::text, 'PAR'::text, 'SIT'::text, 'ANA'::text, 'CSF'::text, 'CSA'::text, 'CSE'::text, 'CSU'::text, 'CSC'::text, 'CSM'::text, 'CSG'::text, 'CSH'::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,
      'compta'::text AS schema
     FROM compta.t_classes,
      compta.t_listes_tables
    WHERE t_classes.table_id = t_listes_tables.oid AND (t_listes_tables.code = ANY (ARRAY['CPT'::text, 'JRN'::text, 'PAR'::text, 'SIT'::text, 'ANA'::text, 'CSF'::text, 'CSA'::text, 'CSE'::text, 'CSU'::text, 'CSC'::text, 'CSM'::text, 'CSG'::text, 'CSH'::text])) AND t_classes.sequence >= 1
  UNION
   SELECT t_listes_tables.oid AS table_id,
      (-1) AS sequence,
      'Nouvelle classe'::text AS texte,
      t_listes_tables.texte AS sort_1,
      0 AS sort_2,
      (-1)::bigint AS classe_id,
      '2'::text AS lvl,
      ''::text AS code,
      'compta'::text AS schema
     FROM compta.t_listes_tables
    WHERE t_listes_tables.code = ANY (ARRAY['CPT'::text, 'JRN'::text, 'PAR'::text, 'SIT'::text, 'ANA'::text, 'CSF'::text, 'CSA'::text, 'CSE'::text, 'CSU'::text, 'CSC'::text, 'CSM'::text, 'CSG'::text, 'CSH'::text])
    ORDER BY 4, 5;