1 /*------------------------------------------------------------------------- 2 * 3 * genbki.h 4 * Required include file for all POSTGRES catalog header files 5 * 6 * genbki.h defines CATALOG(), BKI_BOOTSTRAP and related macros 7 * so that the catalog header files can be read by the C compiler. 8 * (These same words are recognized by genbki.pl to build the BKI 9 * bootstrap file from these header files.) 10 * 11 * 12 * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group 13 * Portions Copyright (c) 1994, Regents of the University of California 14 * 15 * src/include/catalog/genbki.h 16 * 17 *------------------------------------------------------------------------- 18 */ 19 #ifndef GENBKI_H 20 #define GENBKI_H 21 22 /* Introduces a catalog's structure definition */ 23 #define CATALOG(name,oid,oidmacro) typedef struct CppConcat(FormData_,name) 24 25 /* Options that may appear after CATALOG (on the same line) */ 26 #define BKI_BOOTSTRAP 27 #define BKI_SHARED_RELATION 28 #define BKI_ROWTYPE_OID(oid,oidmacro) 29 #define BKI_SCHEMA_MACRO 30 31 /* Options that may appear after an attribute (on the same line) */ 32 #define BKI_FORCE_NULL 33 #define BKI_FORCE_NOT_NULL 34 /* Specifies a default value for a catalog field */ 35 #define BKI_DEFAULT(value) 36 /* Specifies a default value for auto-generated array types */ 37 #define BKI_ARRAY_DEFAULT(value) 38 /* 39 * Indicates that the attribute contains OIDs referencing the named catalog; 40 * can be applied to columns of oid, regproc, oid[], or oidvector type. 41 * genbki.pl uses this to know how to perform name lookups in the initial 42 * data (if any), and it also feeds into regression-test validity checks. 43 * The _OPT suffix indicates that values can be zero instead of 44 * a valid OID reference. 45 */ 46 #define BKI_LOOKUP(catalog) 47 #define BKI_LOOKUP_OPT(catalog) 48 49 /* 50 * These lines are processed by genbki.pl to create the statements 51 * the bootstrap parser will turn into BootstrapToastTable commands. 52 * Each line specifies the system catalog that needs a toast table, 53 * the OID to assign to the toast table, and the OID to assign to the 54 * toast table's index. The reason we hard-wire these OIDs is that we 55 * need stable OIDs for shared relations, and that includes toast tables 56 * of shared relations. 57 * 58 * The macro definition is just to keep the C compiler from spitting up. 59 */ 60 #define DECLARE_TOAST(name,toastoid,indexoid) extern int no_such_variable 61 62 /* 63 * These lines are processed by genbki.pl to create the statements 64 * the bootstrap parser will turn into DefineIndex calls. 65 * 66 * The keyword is DECLARE_INDEX or DECLARE_UNIQUE_INDEX or 67 * DECLARE_UNIQUE_INDEX_PKEY. ("PKEY" marks the index as being the catalog's 68 * primary key; currently this is only cosmetically different from a regular 69 * unique index. By convention, we usually make a catalog's OID column its 70 * pkey, if it has one.) The first two arguments are the index's name and 71 * OID, the rest is much like a standard 'create index' SQL command. 72 * 73 * For each index, we also provide a #define for its OID. References to 74 * the index in the C code should always use these #defines, not the actual 75 * index name (much less the numeric OID). 76 * 77 * The macro definitions are just to keep the C compiler from spitting up. 78 */ 79 #define DECLARE_INDEX(name,oid,decl) extern int no_such_variable 80 #define DECLARE_UNIQUE_INDEX(name,oid,decl) extern int no_such_variable 81 #define DECLARE_UNIQUE_INDEX_PKEY(name,oid,decl) extern int no_such_variable 82 83 /* 84 * These lines are processed by genbki.pl to create a table for use 85 * by the pg_get_catalog_foreign_keys() function. We do not have any 86 * mechanism that actually enforces foreign-key relationships in the 87 * system catalogs, but it is still useful to record the intended 88 * relationships in a machine-readable form. 89 * 90 * The keyword is DECLARE_FOREIGN_KEY[_OPT] or DECLARE_ARRAY_FOREIGN_KEY[_OPT]. 91 * The first argument is a parenthesized list of the referencing columns; 92 * the second, the name of the referenced table; the third, a parenthesized 93 * list of the referenced columns. Use of the ARRAY macros means that the 94 * last referencing column is an array, each of whose elements is supposed 95 * to match some entry in the last referenced column. Use of the OPT suffix 96 * indicates that the referencing column(s) can be zero instead of a valid 97 * reference. 98 * 99 * Columns that are marked with a BKI_LOOKUP rule do not need an explicit 100 * DECLARE_FOREIGN_KEY macro, as genbki.pl can infer the FK relationship 101 * from that. Thus, these macros are only needed in special cases. 102 * 103 * The macro definitions are just to keep the C compiler from spitting up. 104 */ 105 #define DECLARE_FOREIGN_KEY(cols,reftbl,refcols) extern int no_such_variable 106 #define DECLARE_FOREIGN_KEY_OPT(cols,reftbl,refcols) extern int no_such_variable 107 #define DECLARE_ARRAY_FOREIGN_KEY(cols,reftbl,refcols) extern int no_such_variable 108 #define DECLARE_ARRAY_FOREIGN_KEY_OPT(cols,reftbl,refcols) extern int no_such_variable 109 110 /* The following are never defined; they are here only for documentation. */ 111 112 /* 113 * Variable-length catalog fields (except possibly the first not nullable one) 114 * should not be visible in C structures, so they are made invisible by #ifdefs 115 * of an undefined symbol. See also the BOOTCOL_NULL_AUTO code in bootstrap.c 116 * for how this is handled. 117 */ 118 #undef CATALOG_VARLEN 119 120 /* 121 * There is code in some catalog headers that needs to be visible to clients, 122 * but we don't want clients to include the full header because of safety 123 * issues with other code in the header. To handle that, surround code that 124 * should be visible to clients with "#ifdef EXPOSE_TO_CLIENT_CODE". That 125 * instructs genbki.pl to copy the section when generating the corresponding 126 * "_d" header, which can be included by both client and backend code. 127 */ 128 #undef EXPOSE_TO_CLIENT_CODE 129 130 #endif /* GENBKI_H */ 131