format_type()

返回数据类型可读名称的函数

format_type() 是一个系统函数,它根据数据类型的 OID 和(如果适用)类型修饰符来返回该数据类型的可读名称。

format_type()PostgreSQL 7.1 中添加。

用法

format_type ( type oid, typemod integer ) → text

如果没有类型修饰符,则应提供 NULL

如果不存在与指定的 OID / 类型修饰符组合匹配的数据类型,则返回字符串 "???"。

format_type() 主要用于查询 系统目录 关系。

变更历史

示例

format_type() 的基本用法示例,此处返回关系中列的名称和数据类型

postgres=# SELECT attname, format_type(a.atttypid, a.atttypmod)
             FROM pg_attribute a
            WHERE a.attrelid = 'foo'::regclass
              AND attnum > 0;
 attname | format_type
---------+-------------
 id      | integer
 val     | text
(2 rows)

尝试检索不存在的数据类型的名称

postgres=# SELECT format_type(999, NULL);
 format_type
-------------
 ???
(1 row)

分类

数据类型, 系统目录, 系统函数

另请参阅

pg_type_is_visible(), to_regtype(), to_regtypemod()

反馈

请在此处提交关于 "format_type()" 的任何评论、建议或更正。here