4 The catalog pg_attribute stores information about table columns. There
5 will be exactly one pg_attribute row for every column in every table in
6 the database. (There will also be attribute entries for indexes, and
7 indeed all objects that have pg_class entries.)
9 The term attribute is equivalent to column and is used for historical
12 Table 52.7. pg_attribute Columns
18 attrelid oid (references pg_class.oid)
20 The table this column belongs to
26 atttypid oid (references pg_type.oid)
28 The data type of this column (zero for a dropped column)
32 A copy of pg_type.typlen of this column's type
36 The number of the column. Ordinary columns are numbered from 1 up.
37 System columns, such as ctid, have (arbitrary) negative numbers.
41 atttypmod records type-specific data supplied at table creation time
42 (for example, the maximum length of a varchar column). It is passed to
43 type-specific input functions and length coercion functions. The value
44 will generally be -1 for types that do not need atttypmod.
48 Number of dimensions, if the column is an array type; otherwise 0.
49 (Presently, the number of dimensions of an array is not enforced, so
50 any nonzero value effectively means “it's an array”.)
54 A copy of pg_type.typbyval of this column's type
58 A copy of pg_type.typalign of this column's type
62 Normally a copy of pg_type.typstorage of this column's type. For
63 TOAST-able data types, this can be altered after column creation to
64 control storage policy.
68 The current compression method of the column. Typically this is '\0' to
69 specify use of the current default setting (see
70 default_toast_compression). Otherwise, 'p' selects pglz compression,
71 while 'l' selects LZ4 compression. However, this field is ignored
72 whenever attstorage does not allow compression.
76 This column has a (possibly invalid) not-null constraint.
80 This column has a default expression or generation expression, in which
81 case there will be a corresponding entry in the pg_attrdef catalog that
82 actually defines the expression. (Check attgenerated to determine
83 whether this is a default or a generation expression.)
87 This column has a value which is used where the column is entirely
88 missing from the row, as happens when a column is added with a
89 non-volatile DEFAULT value after the row is created. The actual value
90 used is stored in the attmissingval column.
94 If a zero byte (''), then not an identity column. Otherwise, a =
95 generated always, d = generated by default.
99 If a zero byte (''), then not a generated column. Otherwise, s =
100 stored, v = virtual. A stored generated column is physically stored
101 like a normal column. A virtual generated column is physically stored
102 as a null value, with the actual value being computed at run time.
106 This column has been dropped and is no longer valid. A dropped column
107 is still physically present in the table, but is ignored by the parser
108 and so cannot be accessed via SQL.
112 This column is defined locally in the relation. Note that a column can
113 be locally defined and inherited simultaneously.
117 The number of direct ancestors this column has. A column with a nonzero
118 number of ancestors cannot be dropped nor renamed.
120 attcollation oid (references pg_collation.oid)
122 The defined collation of the column, or zero if the column is not of a
127 attstattarget controls the level of detail of statistics accumulated
128 for this column by ANALYZE. A zero value indicates that no statistics
129 should be collected. A null value says to use the system default
130 statistics target. The exact meaning of positive values is data
131 type-dependent. For scalar data types, attstattarget is both the target
132 number of “most common values” to collect, and the target number of
133 histogram bins to create.
137 Column-level access privileges, if any have been granted specifically
142 Attribute-level options, as “keyword=value” strings
146 Attribute-level foreign data wrapper options, as “keyword=value”
149 attmissingval anyarray
151 This column has a one element array containing the value used when the
152 column is entirely missing from the row, as happens when the column is
153 added with a non-volatile DEFAULT value after the row is created. The
154 value is only used when atthasmissing is true. If there is no value the
157 In a dropped column's pg_attribute entry, atttypid is reset to zero,
158 but attlen and the other fields copied from pg_type are still valid.
159 This arrangement is needed to cope with the situation where the dropped
160 column's data type was later dropped, and so there is no pg_type row
161 anymore. attlen and the other fields can be used to interpret the
162 contents of a row of the table.