pg_attribute

The pg_attribute catalog provides information about table columns.

Column name Data type Description
attrelid oid (references pg_class.oid) The table to which this column belongs.
attname name The column name.
atttypid oid (references pg_type.oid) The data type of the column.
0 – A dropped column.
attlen int2 The length of the column’s data type, copied from pg_type.typlen.
attnum int2 The column number. Ordinary columns start from 1. System columns (e.g., ctid) have negative numbers.
atttypmod int4 Type-specific data supplied at table creation (e.g., max length of a varchar).
-1 – Not applicable.
attndims int2 The number of array dimensions.
0 – Not an array.
attbyval bool Specifies whether the column’s data type is passed by value, copied from pg_type.typbyval.
attalign char The alignment requirement of the column’s data type, copied from pg_type.typalign.
attstorage char The storage strategy for the column’s data type, copied from pg_type.typstorage. The value can be changed for TOAST-able types.
attcompression char A compression method.
The possible values are:
  • 0 – Default.
  • p – pglz.
  • l – LZ4.

Note: The compression method is ignored if attstorage does not support compression.
attnotnull bool Specifies whether this column has a NOT NULL constraint.
atthasdef bool Specifies whether the column has a default or generated expression (see pg_attrdef).
atthasmissing bool Specifies whether the column has a value used when the column is missing in a row. Stored in attmissingval.
attidentity char An identity column indicator.
The possible values are:
  • Empty string – Not an identity column.
  • a – Always generated.
  • d – Generated by default.
attgenerated char A generated column type.
The possible values are:
  • Empty string – Not a generated column.
  • a – Stored.
  • v – Virtual.
attisdropped bool Specifies whether this column has been dropped. Dropped columns exist physically, but they are ignored.
attislocal bool Specifies whether the column is defined locally in the table or inherited.
attinhcount int2 The number of direct ancestors in the column. Columns with ancestors cannot be dropped or renamed.
attcollation oid (references pg_collation.oid) The collation of the column.
0 – Not collatable.
attstattarget int2 The detail level for statistics collected by ANALYZE.
The possible values are:
  • 0 – No statistics is collected.
  • NULL – System default statistics.
attacl aclitem[] Column-level access privileges, if any.
attoptions text[] Attribute-level options as keyword=value strings.
attfdwoptions text[] Foreign data wrapper options as keyword=value strings.
attmissingval anyarray An array containing a value used when the column is entirely missing is a row. The value is used if atthasmissing is TRUE.