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,
      ''::text AS sort_2,
      0 AS classe_id,
      '1'::text AS lvl,
      ''::text AS code,
      'eco'::text AS schema
     FROM eco.t_listes_tables
       LEFT JOIN eco.t_classes ON t_classes.table_id = t_listes_tables.oid
    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::text AS sort_2,
      t_classes.oid AS classe_id,
      '2'::text AS lvl,
      t_classes.code,
      'eco'::text AS schema
     FROM eco.t_classes
       JOIN eco.t_listes_tables ON t_classes.table_id = t_listes_tables.oid
    WHERE t_classes.table_id = t_listes_tables.oid 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,
      '1'::text AS sort_2,
      (-1) AS classe_id,
      '2'::text AS lvl,
      ''::text AS code,
      'eco'::text AS schema
     FROM eco.t_listes_tables
    ORDER BY 4, 5;