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 AS classe_id,
      '1'::text AS lvl,
      ''::text AS code,
      'pmsi'::text AS schema
     FROM pmsi.t_listes_tables
       LEFT JOIN pmsi.t_classes ON t_classes.table_id = t_listes_tables.oid
    WHERE t_listes_tables.code = ANY (ARRAY['DIAG'::text, 'ACTE'::text, 'PRESTA'::text, 'GHM'::text, 'MEDECIN'::text, 'LPP'::text, 'UM'::text, 'COMED'::text, 'UCD'::text, 'AGE'::text, 'DURSEJ'::text, 'CODEPOST'::text, 'TYPEFACT'::text, 'PERSO_RSS1'::text, 'EXPERTCTL'::text, 'INDICATIONUCD'::text, 'UF'::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,
      'pmsi'::text AS schema
     FROM pmsi.t_classes,
      pmsi.t_listes_tables
    WHERE t_classes.table_id = t_listes_tables.oid AND (t_listes_tables.code = ANY (ARRAY['DIAG'::text, 'ACTE'::text, 'PRESTA'::text, 'GHM'::text, 'MEDECIN'::text, 'LPP'::text, 'UM'::text, 'COMED'::text, 'UCD'::text, 'AGE'::text, 'DURSEJ'::text, 'CODEPOST'::text, 'TYPEFACT'::text, 'PERSO_RSS1'::text, 'EXPERTCTL'::text, 'INDICATIONUCD'::text, 'UF'::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 AS classe_id,
      '2'::text AS lvl,
      ''::text AS code,
      'pmsi'::text AS schema
     FROM pmsi.t_listes_tables
    WHERE t_listes_tables.code = ANY (ARRAY['DIAG'::text, 'ACTE'::text, 'PRESTA'::text, 'GHM'::text, 'MEDECIN'::text, 'LPP'::text, 'UM'::text, 'COMED'::text, 'UCD'::text, 'AGE'::text, 'DURSEJ'::text, 'CODEPOST'::text, 'TYPEFACT'::text, 'PERSO_RSS1'::text, 'EXPERTCTL'::text, 'INDICATIONUCD'::text, 'UF'::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 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'::integer AS sequence,
      'Nouvelle classe'::text AS texte,
      t_listes_tables.texte AS sort_1,
      0 AS sort_2,
      '-1'::integer 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;