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::bigint AS sort_2,
      0::bigint AS classe_id,
      '1'::text AS lvl,
      ''::text AS code,
      'activite'::text AS schema
     FROM activite.t_listes_tables
       LEFT JOIN activite.t_classes ON t_classes.table_id = t_listes_tables.oid
    WHERE t_listes_tables.code = ANY (ARRAY['CODEPOST'::text, 'ACTIVITE'::text, 'AGE'::text, 'DURSEJ'::text, 'SERVICE_F'::text, 'ETAGE'::text, 'LIT'::text, 'MEDECIN'::text, 'MEDECIN_TRAITANT'::text, 'RUBRIQUEX'::text, 'ACTE'::text, 'PERSO_SEJ1'::text, 'COMPTE'::text, 'BUDGETCLE'::text, 'GHM'::text, 'GME'::text, 'TSE'::text, 'ETATSEJOUR'::text, 'PRESTA_C'::text, 'UM'::text, 'UF'::text, 'REJETNOEMI'::text, 'TIERSP'::text, 'RUBRIQUE'::text, 'ACTE'::text, 'PERSO_SEJ1'::text, 'COMPTE'::text, 'BUDGETCLE'::text, 'GHM'::text, 'GME'::text, 'TYPESEJOUR'::text, 'FORMEACTIVITE'::text, 'GHMGME'::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,
      'activite'::text AS schema
     FROM activite.t_classes,
      activite.t_listes_tables
    WHERE t_classes.table_id = t_listes_tables.oid AND (t_listes_tables.code = ANY (ARRAY['CODEPOST'::text, 'ACTIVITE'::text, 'AGE'::text, 'DURSEJ'::text, 'SERVICE_F'::text, 'ETAGE'::text, 'LIT'::text, 'MEDECIN'::text, 'MEDECIN_TRAITANT'::text, 'RUBRIQUEX'::text, 'ACTE'::text, 'PERSO_SEJ1'::text, 'COMPTE'::text, 'BUDGETCLE'::text, 'GHM'::text, 'GHM'::text, 'TSE'::text, 'ETATSEJOUR'::text, 'PRESTA_C'::text, 'UM'::text, 'UF'::text, 'REJETNOEMI'::text, 'TIERSP'::text, 'RUBRIQUE'::text, 'ACTE'::text, 'PERSO_SEJ1'::text, 'COMPTE'::text, 'BUDGETCLE'::text, 'GHM'::text, 'GME'::text, 'TYPESEJOUR'::text, 'FORMEACTIVITE'::text, 'GHMGME'::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::bigint AS sort_2,
      (-1)::bigint AS classe_id,
      '2'::text AS lvl,
      ''::text AS code,
      'activite'::text AS schema
     FROM activite.t_listes_tables
    WHERE t_listes_tables.code = ANY (ARRAY['CODEPOST'::text, 'ACTIVITE'::text, 'AGE'::text, 'DURSEJ'::text, 'SERVICE_F'::text, 'ETAGE'::text, 'LIT'::text, 'MEDECIN'::text, 'MEDECIN_TRAITANT'::text, 'RUBRIQUEX'::text, 'ACTE'::text, 'PERSO_SEJ1'::text, 'COMPTE'::text, 'BUDGETCLE'::text, 'GHM'::text, 'GHM'::text, 'TSE'::text, 'ETATSEJOUR'::text, 'PRESTA_C'::text, 'UM'::text, 'UF'::text, 'REJETNOEMI'::text, 'TIERSP'::text, 'RUBRIQUE'::text, 'ACTE'::text, 'PERSO_SEJ1'::text, 'COMPTE'::text, 'BUDGETCLE'::text, 'GHM'::text, 'GME'::text, 'TYPESEJOUR'::text, 'FORMEACTIVITE'::text, 'GHMGME'::text])
  UNION
   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::bigint AS sort_2,
      0::bigint AS classe_id,
      '1'::text AS lvl,
      ''::text AS code,
      'base'::text AS schema
     FROM base.t_listes_tables
       LEFT JOIN base.t_classes ON t_classes.table_id = t_listes_tables.oid
    WHERE t_listes_tables.code = ANY (ARRAY['FINESS'::text, 'POLE'::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,
      '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['FINESS'::text, 'POLE'::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::bigint AS sort_2,
      (-1)::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['FINESS'::text, 'POLE'::text])
    ORDER BY 4, 5;