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_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
        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
  WHERE ((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 pg_catalog.pg_table_is_visible(c.oid)
    AND ((cmd.cmd ~ 'S' AND n.nspname = 'pg_catalog')
        OR n.nspname NOT IN ('pg_catalog', 'pg_toast'))
  ORDER BY n.nspname,c.relname