SELECT c.oid,
       CASE c.relkind
         WHEN 'r' THEN 'Table "' || n.nspname || '.' || c.relname || '"'
         WHEN 'v' THEN 'View "' || n.nspname || '.' || c.relname || '"'
         WHEN 'S' THEN 'Sequence "' || n.nspname || '.' || c.relname || '"'
         WHEN 'i' THEN 'Index "' || n.nspname || '.' || c.relname || '"'
         WHEN 's' THEN 'Special relation "' || n.nspname || '.' || c.relname || '"'
         WHEN 't' THEN 'TOAST table "' || n.nspname || '.' || c.relname || '"'
         WHEN 'c' THEN 'Composite type "' || n.nspname || '.' || c.relname || '"'
         ELSE c.relkind || ' "' || n.nspname || '.' || c.relname || '"'
       END AS title
  FROM pg_catalog.pg_class c
       LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace,
       (SELECT $1 AS cmd) AS cmd,
       pg_catalog.pg_name_pattern($2) AS (schpat text, tabpat text)
 WHERE n.nspname ~ schpat
       AND c.relname ~ tabpat
 ORDER BY n.nspname, c.relname