列出数据库使用的所有数据类型

显示当前数据库使用的内置数据类型

场景:您想查看当前数据库使用了哪些内置数据类型。

解决方案:使用此系统目录查询

    SELECT DISTINCT(pg_catalog.format_type(t.oid, NULL)) AS data_type
      FROM pg_catalog.pg_attribute a
INNER JOIN pg_catalog.pg_class c
        ON a.attrelid = c.oid
INNER JOIN pg_catalog.pg_namespace cn
        ON cn.oid = c.relnamespace
INNER JOIN pg_catalog.pg_type t ON t.oid = a.atttypid
INNER JOIN pg_catalog.pg_namespace tn
        ON tn.oid = t.typnamespace
     WHERE (cn.nspname != 'pg_catalog'
           AND cn.nspname != 'information_schema')
       AND tn.nspname = 'pg_catalog'
       AND a.attnum > 0
       AND NOT a.attisdropped
       AND pg_catalog.pg_type_is_visible(t.oid)
       AND NOT EXISTS (
           SELECT NULL
             FROM pg_catalog.pg_foreign_table ft
            WHERE ft.ftrelid=c.oid
           )
       AND c.relkind='r'
  ORDER BY 1

输出将如下所示

          data_type          
-----------------------------
 boolean
 character
 character varying
 date
 inet
 integer
 numeric
 smallint
 text
 timestamp without time zone
 timestamp with time zone
 tsvector
(12 rows)