SELECT n.nspname AS "Schema",
        c.relname AS "Name",
        CASE c.relkind
          WHEN 'r' THEN pg_catalog.pg_gettext('table')
          WHEN 'v' THEN pg_catalog.pg_gettext('view')
          WHEN 'i' THEN pg_catalog.pg_gettext('index')
          WHEN 's' THEN pg_catalog.pg_gettext('sequence')
          WHEN 'S' THEN pg_catalog.pg_gettext('special')
        END AS "Type",
        u.usename AS "Owner",
        c2.relname AS "Table"
   FROM (SELECT $1 AS cmd) AS cmd,
        pg_catalog.pg_name_pattern($2) AS (schpat text, relpat text),
        pg_catalog.pg_namespace n,
        pg_catalog.pg_class c
        LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid
        LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid
        LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner
  WHERE c.relnamespace = n.oid
    AND ((cmd.cmd ~ 't' AND c.relkind = 'r')
        OR (cmd.cmd ~ 'i' AND c.relkind = 'i')
        OR (cmd.cmd ~ 'v' AND c.relkind = 'v')
        OR (cmd.cmd ~ 's' AND c.relkind = 's'))
    AND n.nspname ~ schpat
    AND c.relname ~ relpat
  ORDER BY 1,2