PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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-2026, 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 */
38
40{
41 Oid attrelid BKI_LOOKUP(pg_class); /* OID of relation containing
42 * this attribute */
43 NameData attname; /* name of attribute */
44
45 /*
46 * atttypid is the OID of the instance in Catalog Class pg_type that
47 * defines the data type of this attribute (e.g. int4). Information in
48 * that instance is redundant with the attlen, attbyval, and attalign
49 * attributes of this instance, so they had better match or Postgres will
50 * fail. In an entry for a dropped column, this field is set to zero
51 * since the pg_type entry may no longer exist; but we rely on attlen,
52 * attbyval, and attalign to still tell us how large the values in the
53 * table are.
54 */
56
57 /*
58 * attlen is a copy of the typlen field from pg_type for this attribute.
59 * See atttypid comments above.
60 */
62
63 /*
64 * attnum is the "attribute number" for the attribute: A value that
65 * uniquely identifies this attribute within its class. For user
66 * attributes, Attribute numbers are greater than 0 and not greater than
67 * the number of attributes in the class. I.e. if the Class pg_class says
68 * that Class XYZ has 10 attributes, then the user attribute numbers in
69 * Class pg_attribute must be 1-10.
70 *
71 * System attributes have attribute numbers less than 0 that are unique
72 * within the class, but not constrained to any particular range.
73 *
74 * Note that (attnum - 1) is often used as the index to an array.
75 */
77
78 /*
79 * atttypmod records type-specific data supplied at table creation time
80 * (for example, the max length of a varchar field). It is passed to
81 * type-specific input and output functions as the third argument. The
82 * value will generally be -1 for types that do not need typmod.
83 */
84 int32 atttypmod BKI_DEFAULT(-1);
85
86 /*
87 * attndims is the declared number of dimensions, if an array type,
88 * otherwise zero.
89 */
91
92 /*
93 * attbyval is a copy of the typbyval field from pg_type for this
94 * attribute. See atttypid comments above.
95 */
97
98 /*
99 * attalign is a copy of the typalign field from pg_type for this
100 * attribute. See atttypid comments above.
101 */
103
104 /*----------
105 * attstorage tells for VARLENA attributes, what the heap access
106 * methods can do to it if a given tuple doesn't fit into a page.
107 * Possible values are as for pg_type.typstorage (see TYPSTORAGE macros).
108 *----------
109 */
111
112 /*
113 * attcompression sets the current compression method of the attribute.
114 * Typically this is InvalidCompressionMethod ('\0') to specify use of the
115 * current default setting (see default_toast_compression). Otherwise,
116 * 'p' selects pglz compression, while 'l' selects LZ4 compression.
117 * However, this field is ignored whenever attstorage does not allow
118 * compression.
119 */
120 char attcompression BKI_DEFAULT('\0');
121
122 /*
123 * Whether a (possibly invalid) not-null constraint exists for the column
124 */
126
127 /* Has DEFAULT value or not */
129
130 /* Has a missing value or not */
131 bool atthasmissing BKI_DEFAULT(f);
132
133 /* One of the ATTRIBUTE_IDENTITY_* constants below, or '\0' */
134 char attidentity BKI_DEFAULT('\0');
135
136 /* One of the ATTRIBUTE_GENERATED_* constants below, or '\0' */
137 char attgenerated BKI_DEFAULT('\0');
138
139 /* Is dropped (ie, logically invisible) or not */
140 bool attisdropped BKI_DEFAULT(f);
141
142 /*
143 * This flag specifies whether this column has ever had a local
144 * definition. It is set for normal non-inherited columns, but also for
145 * columns that are inherited from parents if also explicitly listed in
146 * CREATE TABLE INHERITS. It is also set when inheritance is removed from
147 * a table with ALTER TABLE NO INHERIT. If the flag is set, the column is
148 * not dropped by a parent's DROP COLUMN even if this causes the column's
149 * attinhcount to become zero.
150 */
151 bool attislocal BKI_DEFAULT(t);
152
153 /* Number of times inherited from direct parent relation(s) */
155
156 /* attribute's collation, if any */
158
159#ifdef CATALOG_VARLEN /* variable-length/nullable fields start here */
160 /* NOTE: The following fields are not present in tuple descriptors. */
161
162 /*
163 * attstattarget is the target number of statistics datapoints to collect
164 * during VACUUM ANALYZE of this column. A zero here indicates that we do
165 * not wish to collect any stats about this column. A null value here
166 * indicates that no value has been explicitly set for this column, so
167 * ANALYZE should use the default setting.
168 *
169 * int16 is sufficient for the current max value (MAX_STATISTICS_TARGET).
170 */
171 int16 attstattarget BKI_DEFAULT(_null_) BKI_FORCE_NULL;
172
173 /* Column-level access permissions */
175
176 /* Column-level options */
177 text attoptions[1] BKI_DEFAULT(_null_);
178
179 /* Column-level FDW options */
180 text attfdwoptions[1] BKI_DEFAULT(_null_);
181
182 /*
183 * Missing value for added columns. This is a one element array which lets
184 * us store a value of the attribute type here.
185 */
186 anyarray attmissingval BKI_DEFAULT(_null_);
187#endif
189
191
192/*
193 * ATTRIBUTE_FIXED_PART_SIZE is the size of the fixed-layout,
194 * guaranteed-not-null part of a pg_attribute row. This is in fact as much
195 * of the row as gets copied into tuple descriptors, so don't expect you
196 * can access the variable-length fields except in a real tuple!
197 */
198#define ATTRIBUTE_FIXED_PART_SIZE \
199 (offsetof(FormData_pg_attribute,attcollation) + sizeof(Oid))
200
201/* ----------------
202 * Form_pg_attribute corresponds to a pointer to a tuple with
203 * the format of pg_attribute relation.
204 * ----------------
205 */
207
208/*
209 * FormExtraData_pg_attribute contains (some of) the fields that are not in
210 * FormData_pg_attribute because they are excluded by CATALOG_VARLEN. It is
211 * meant to be used by DDL code so that the combination of
212 * FormData_pg_attribute (often via tuple descriptor) and
213 * FormExtraData_pg_attribute can be used to pass around all the information
214 * about an attribute. Fields can be included here as needed.
215 */
221
224
227
228#ifdef EXPOSE_TO_CLIENT_CODE
229
230#define ATTRIBUTE_IDENTITY_ALWAYS 'a'
231#define ATTRIBUTE_IDENTITY_BY_DEFAULT 'd'
232
233#define ATTRIBUTE_GENERATED_STORED 's'
234#define ATTRIBUTE_GENERATED_VIRTUAL 'v'
235
236#endif /* EXPOSE_TO_CLIENT_CODE */
237
238#endif /* PG_ATTRIBUTE_H */
int16_t int16
Definition c.h:553
int32_t int32
Definition c.h:554
#define BEGIN_CATALOG_STRUCT
Definition genbki.h:37
#define DECLARE_UNIQUE_INDEX_PKEY(name, oid, oidmacro, tblname, decl)
Definition genbki.h:105
#define BKI_LOOKUP(catalog)
Definition genbki.h:65
#define END_CATALOG_STRUCT
Definition genbki.h:38
#define BKI_DEFAULT(value)
Definition genbki.h:54
#define BKI_LOOKUP_OPT(catalog)
Definition genbki.h:66
#define DECLARE_UNIQUE_INDEX(name, oid, oidmacro, tblname, decl)
Definition genbki.h:104
#define BKI_FORCE_NULL
Definition genbki.h:51
#define CATALOG(name, oid, oidmacro)
Definition genbki.h:42
#define BKI_BOOTSTRAP
Definition genbki.h:45
#define MAKE_SYSCACHE(name, idxname, nbuckets)
Definition genbki.h:146
#define BKI_ROWTYPE_OID(oid, oidmacro)
Definition genbki.h:47
FormData_pg_attribute
BEGIN_CATALOG_STRUCT AttributeRelation_Rowtype_Id BKI_SCHEMA_MACRO
int16 attndims
NameData attname
char attstorage
bool attbyval
char attalign
int16 attnum
int16 attlen
FormData_pg_attribute * Form_pg_attribute
bool attnotnull
unsigned int Oid
static int fb(int x)
Definition c.h:772
Definition c.h:718