A function returning the human-readable name of a data type

format_type() is a system function which returns the human-readable name of a data type from its OID and, if appropriate, the type modifier.

format_type() was added in PostgreSQL 7.1.


format_type ( type oid, typemod integer ) → text

NULL should be provided If no type modifier exists.

If no data type matches the specified OID / type modifier combination. the string "???" is returned.

format_type() is mainly used in queries over system catalog relations.

Change history


Basic usage example for format_type(), here returning the names and data types of columns in a relation:

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)

Attempting to retrieve the name of a non-existent data type:

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


Data type, System catalogue, System function