col_description()

A function returning a column's comment

col_description() is a system function returning a table column's comment.

col_description() was added in PostgreSQL 7.2.

Usage

col_description ( table oid, column integer ) → text

col_description() requires the table name as an OID (this can be easily obtained by casting the table name to regclass), and the column number, which is not necessarily the sequential number of the column; the column number corresponds to the value in pg_attribute's attnum column.

col_description() returns NULL if the specified table column does not have a comment, or if the specified table or column does not exist.

If the table is specified via a regclass cast, an error will be raised if the table is not found.

Change history

Examples

Basic execution of col_description():

postgres=# COMMENT ON COLUMN foo.id IS 'Thingy number';
COMMENT

postgres=# SELECT col_description('foo'::regclass, 1);
 col_description 
-----------------
 Thingy number
(1 row)

postgres=# COMMENT ON COLUMN foo.id IS NULL;
COMMENT

postgres=# SELECT col_description('foo'::regclass, 1);
 col_description 
-----------------
 
(1 row)

Attempting to obtain the column description for a non-existent table:

postgres=# SELECT col_description(9999, 1);
 col_description 
-----------------
 
(1 row)

postgres=# SELECT col_description('not_a_table'::regclass, 1);
ERROR:  relation "not_a_table" does not exist
LINE 1: SELECT col_description('not_a_table'::regclass, 1);

Attempting to obtain the column description for a non-existent column:

postgres=# SELECT col_description('foo'::regclass, 999);
 col_description 
-----------------
 
(1 row)

Categories

System function

See also

obj_description(), shobj_description(), COMMENT ON