PostgreSQL Source Code git master
pg_attribute.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * pg_attribute.h
4 * definition of the "attribute" system catalog (pg_attribute)
5 *
6 * The initial contents of pg_attribute are generated at compile time by
7 * genbki.pl, so there is no pg_attribute.dat file. Only "bootstrapped"
8 * relations need be included.
9 *
10 *
11 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
12 * Portions Copyright (c) 1994, Regents of the University of California
13 *
14 * src/include/catalog/pg_attribute.h
15 *
16 * NOTES
17 * The Catalog.pm module reads this file and derives schema
18 * information.
19 *
20 *-------------------------------------------------------------------------
21 */
22#ifndef PG_ATTRIBUTE_H
23#define PG_ATTRIBUTE_H
24
25#include "catalog/genbki.h"
26#include "catalog/pg_attribute_d.h" /* IWYU pragma: export */
27
28/* ----------------
29 * pg_attribute definition. cpp turns this into
30 * typedef struct FormData_pg_attribute
31 *
32 * If you change the following, make sure you change the structs for
33 * system attributes in catalog/heap.c also.
34 * You may need to change catalog/genbki.pl as well.
35 * ----------------
36 */
37CATALOG(pg_attribute,1249,AttributeRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(75,AttributeRelation_Rowtype_Id) BKI_SCHEMA_MACRO
38{
39 Oid attrelid BKI_LOOKUP(pg_class); /* OID of relation containing
40 * this attribute */
41 NameData attname; /* name of attribute */
42
43 /*
44 * atttypid is the OID of the instance in Catalog Class pg_type that
45 * defines the data type of this attribute (e.g. int4). Information in
46 * that instance is redundant with the attlen, attbyval, and attalign
47 * attributes of this instance, so they had better match or Postgres will
48 * fail. In an entry for a dropped column, this field is set to zero
49 * since the pg_type entry may no longer exist; but we rely on attlen,
50 * attbyval, and attalign to still tell us how large the values in the
51 * table are.
52 */
53 Oid atttypid BKI_LOOKUP_OPT(pg_type);
54
55 /*
56 * attlen is a copy of the typlen field from pg_type for this attribute.
57 * See atttypid comments above.
58 */
60
61 /*
62 * attnum is the "attribute number" for the attribute: A value that
63 * uniquely identifies this attribute within its class. For user
64 * attributes, Attribute numbers are greater than 0 and not greater than
65 * the number of attributes in the class. I.e. if the Class pg_class says
66 * that Class XYZ has 10 attributes, then the user attribute numbers in
67 * Class pg_attribute must be 1-10.
68 *
69 * System attributes have attribute numbers less than 0 that are unique
70 * within the class, but not constrained to any particular range.
71 *
72 * Note that (attnum - 1) is often used as the index to an array.
73 */
75
76 /*
77 * atttypmod records type-specific data supplied at table creation time
78 * (for example, the max length of a varchar field). It is passed to
79 * type-specific input and output functions as the third argument. The
80 * value will generally be -1 for types that do not need typmod.
81 */
82 int32 atttypmod BKI_DEFAULT(-1);
83
84 /*
85 * attndims is the declared number of dimensions, if an array type,
86 * otherwise zero.
87 */
89
90 /*
91 * attbyval is a copy of the typbyval field from pg_type for this
92 * attribute. See atttypid comments above.
93 */
95
96 /*
97 * attalign is a copy of the typalign field from pg_type for this
98 * attribute. See atttypid comments above.
99 */
101
102 /*----------
103 * attstorage tells for VARLENA attributes, what the heap access
104 * methods can do to it if a given tuple doesn't fit into a page.
105 * Possible values are as for pg_type.typstorage (see TYPSTORAGE macros).
106 *----------
107 */
109
110 /*
111 * attcompression sets the current compression method of the attribute.
112 * Typically this is InvalidCompressionMethod ('\0') to specify use of the
113 * current default setting (see default_toast_compression). Otherwise,
114 * 'p' selects pglz compression, while 'l' selects LZ4 compression.
115 * However, this field is ignored whenever attstorage does not allow
116 * compression.
117 */
118 char attcompression BKI_DEFAULT('\0');
119
120 /* This flag represents the "NOT NULL" constraint */
122
123 /* Has DEFAULT value or not */
124 bool atthasdef BKI_DEFAULT(f);
125
126 /* Has a missing value or not */
127 bool atthasmissing BKI_DEFAULT(f);
128
129 /* One of the ATTRIBUTE_IDENTITY_* constants below, or '\0' */
130 char attidentity BKI_DEFAULT('\0');
131
132 /* One of the ATTRIBUTE_GENERATED_* constants below, or '\0' */
133 char attgenerated BKI_DEFAULT('\0');
134
135 /* Is dropped (ie, logically invisible) or not */
136 bool attisdropped BKI_DEFAULT(f);
137
138 /*
139 * This flag specifies whether this column has ever had a local
140 * definition. It is set for normal non-inherited columns, but also for
141 * columns that are inherited from parents if also explicitly listed in
142 * CREATE TABLE INHERITS. It is also set when inheritance is removed from
143 * a table with ALTER TABLE NO INHERIT. If the flag is set, the column is
144 * not dropped by a parent's DROP COLUMN even if this causes the column's
145 * attinhcount to become zero.
146 */
147 bool attislocal BKI_DEFAULT(t);
148
149 /* Number of times inherited from direct parent relation(s) */
150 int16 attinhcount BKI_DEFAULT(0);
151
152 /* attribute's collation, if any */
153 Oid attcollation BKI_LOOKUP_OPT(pg_collation);
154
155#ifdef CATALOG_VARLEN /* variable-length/nullable fields start here */
156 /* NOTE: The following fields are not present in tuple descriptors. */
157
158 /*
159 * attstattarget is the target number of statistics datapoints to collect
160 * during VACUUM ANALYZE of this column. A zero here indicates that we do
161 * not wish to collect any stats about this column. A null value here
162 * indicates that no value has been explicitly set for this column, so
163 * ANALYZE should use the default setting.
164 *
165 * int16 is sufficient for the current max value (MAX_STATISTICS_TARGET).
166 */
167 int16 attstattarget BKI_DEFAULT(_null_) BKI_FORCE_NULL;
168
169 /* Column-level access permissions */
170 aclitem attacl[1] BKI_DEFAULT(_null_);
171
172 /* Column-level options */
173 text attoptions[1] BKI_DEFAULT(_null_);
174
175 /* Column-level FDW options */
176 text attfdwoptions[1] BKI_DEFAULT(_null_);
177
178 /*
179 * Missing value for added columns. This is a one element array which lets
180 * us store a value of the attribute type here.
181 */
182 anyarray attmissingval BKI_DEFAULT(_null_);
183#endif
185
186/*
187 * ATTRIBUTE_FIXED_PART_SIZE is the size of the fixed-layout,
188 * guaranteed-not-null part of a pg_attribute row. This is in fact as much
189 * of the row as gets copied into tuple descriptors, so don't expect you
190 * can access the variable-length fields except in a real tuple!
191 */
192#define ATTRIBUTE_FIXED_PART_SIZE \
193 (offsetof(FormData_pg_attribute,attcollation) + sizeof(Oid))
194
195/* ----------------
196 * Form_pg_attribute corresponds to a pointer to a tuple with
197 * the format of pg_attribute relation.
198 * ----------------
199 */
201
202/*
203 * FormExtraData_pg_attribute contains (some of) the fields that are not in
204 * FormData_pg_attribute because they are excluded by CATALOG_VARLEN. It is
205 * meant to be used by DDL code so that the combination of
206 * FormData_pg_attribute (often via tuple descriptor) and
207 * FormExtraData_pg_attribute can be used to pass around all the information
208 * about an attribute. Fields can be included here as needed.
209 */
211{
215
216DECLARE_UNIQUE_INDEX(pg_attribute_relid_attnam_index, 2658, AttributeRelidNameIndexId, pg_attribute, btree(attrelid oid_ops, attname name_ops));
217DECLARE_UNIQUE_INDEX_PKEY(pg_attribute_relid_attnum_index, 2659, AttributeRelidNumIndexId, pg_attribute, btree(attrelid oid_ops, attnum int2_ops));
218
219MAKE_SYSCACHE(ATTNAME, pg_attribute_relid_attnam_index, 32);
220MAKE_SYSCACHE(ATTNUM, pg_attribute_relid_attnum_index, 128);
221
222#ifdef EXPOSE_TO_CLIENT_CODE
223
224#define ATTRIBUTE_IDENTITY_ALWAYS 'a'
225#define ATTRIBUTE_IDENTITY_BY_DEFAULT 'd'
226
227#define ATTRIBUTE_GENERATED_STORED 's'
228#define ATTRIBUTE_GENERATED_VIRTUAL 'v'
229
230#endif /* EXPOSE_TO_CLIENT_CODE */
231
232#endif /* PG_ATTRIBUTE_H */
int16_t int16
Definition: c.h:483
int32_t int32
Definition: c.h:484
#define BKI_LOOKUP(catalog)
Definition: genbki.h:46
#define BKI_FORCE_NULL
Definition: genbki.h:32
#define BKI_BOOTSTRAP
Definition: genbki.h:26
#define BKI_ROWTYPE_OID(oid, oidmacro)
Definition: genbki.h:28
struct FormExtraData_pg_attribute FormExtraData_pg_attribute
FormData_pg_attribute
Definition: pg_attribute.h:184
int16 attndims
Definition: pg_attribute.h:88
NameData attname
Definition: pg_attribute.h:41
Oid atttypid BKI_LOOKUP_OPT(pg_type)
CATALOG(pg_attribute, 1249, AttributeRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(75
DECLARE_UNIQUE_INDEX(pg_attribute_relid_attnam_index, 2658, AttributeRelidNameIndexId, pg_attribute, btree(attrelid oid_ops, attname name_ops))
char attstorage
Definition: pg_attribute.h:108
AttributeRelation_Rowtype_Id BKI_SCHEMA_MACRO
Definition: pg_attribute.h:38
bool attbyval
Definition: pg_attribute.h:94
char attalign
Definition: pg_attribute.h:100
int16 attnum
Definition: pg_attribute.h:74
int16 attlen
Definition: pg_attribute.h:59
MAKE_SYSCACHE(ATTNAME, pg_attribute_relid_attnam_index, 32)
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:200
DECLARE_UNIQUE_INDEX_PKEY(pg_attribute_relid_attnum_index, 2659, AttributeRelidNumIndexId, pg_attribute, btree(attrelid oid_ops, attnum int2_ops))
int32 atttypmod BKI_DEFAULT(-1)
bool attnotnull
Definition: pg_attribute.h:121
unsigned int Oid
Definition: postgres_ext.h:32
Definition: c.h:698
Definition: c.h:644