SELECT n.nspname as "Schema",
       pg_catalog.format_type(t.oid, NULL) AS "Name",
       t.typname AS "Internal name",
       CASE WHEN t.typrelid != 0
              THEN CAST('tuple' AS pg_catalog.text)
            WHEN t.typlen < 0
              THEN CAST('var' AS pg_catalog.text)
            ELSE CAST(t.typlen AS pg_catalog.text)
       END AS "Size",
       pg_catalog.obj_description(t.oid, 'pg_type') as "Description"
FROM pg_catalog.pg_type t
     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace,
     (SELECT $1 AS cmd) AS cmd,
     pg_catalog.pg_name_pattern($2) AS (schpat text, typpat text)
WHERE (t.typrelid = 0
      OR (SELECT c.relkind = 'c'
            FROM pg_catalog.pg_class c
           WHERE c.oid = t.typrelid))
      AND n.nspname ~ schpat
      AND (t.typname ~ typpat
       OR pg_catalog.format_type(t.oid, NULL) ~ typpat)
ORDER BY 1, 2