pg_constraint.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*-------------------------------------------------------------------------
  2. *
  3. * pg_constraint.h
  4. * definition of the system "constraint" relation (pg_constraint)
  5. * along with the relation's initial contents.
  6. *
  7. *
  8. * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
  9. * Portions Copyright (c) 1994, Regents of the University of California
  10. *
  11. * src/include/catalog/pg_constraint.h
  12. *
  13. * NOTES
  14. * the genbki.pl script reads this file and generates .bki
  15. * information from the DATA() statements.
  16. *
  17. *-------------------------------------------------------------------------
  18. */
  19. #ifndef PG_CONSTRAINT_H
  20. #define PG_CONSTRAINT_H
  21. #include "catalog/genbki.h"
  22. /* ----------------
  23. * pg_constraint definition. cpp turns this into
  24. * typedef struct FormData_pg_constraint
  25. * ----------------
  26. */
  27. #define ConstraintRelationId 2606
  28. CATALOG(pg_constraint,2606)
  29. {
  30. /*
  31. * conname + connamespace is deliberately not unique; we allow, for
  32. * example, the same name to be used for constraints of different
  33. * relations. This is partly for backwards compatibility with past
  34. * Postgres practice, and partly because we don't want to have to obtain a
  35. * global lock to generate a globally unique name for a nameless
  36. * constraint. We associate a namespace with constraint names only for
  37. * SQL-spec compatibility.
  38. */
  39. NameData conname; /* name of this constraint */
  40. Oid connamespace; /* OID of namespace containing constraint */
  41. char contype; /* constraint type; see codes below */
  42. bool condeferrable; /* deferrable constraint? */
  43. bool condeferred; /* deferred by default? */
  44. bool convalidated; /* constraint has been validated? */
  45. /*
  46. * conrelid and conkey are only meaningful if the constraint applies to a
  47. * specific relation (this excludes domain constraints and assertions).
  48. * Otherwise conrelid is 0 and conkey is NULL.
  49. */
  50. Oid conrelid; /* relation this constraint constrains */
  51. /*
  52. * contypid links to the pg_type row for a domain if this is a domain
  53. * constraint. Otherwise it's 0.
  54. *
  55. * For SQL-style global ASSERTIONs, both conrelid and contypid would be
  56. * zero. This is not presently supported, however.
  57. */
  58. Oid contypid; /* domain this constraint constrains */
  59. /*
  60. * conindid links to the index supporting the constraint, if any;
  61. * otherwise it's 0. This is used for unique, primary-key, and exclusion
  62. * constraints, and less obviously for foreign-key constraints (where the
  63. * index is a unique index on the referenced relation's referenced
  64. * columns). Notice that the index is on conrelid in the first case but
  65. * confrelid in the second.
  66. */
  67. Oid conindid; /* index supporting this constraint */
  68. /*
  69. * These fields, plus confkey, are only meaningful for a foreign-key
  70. * constraint. Otherwise confrelid is 0 and the char fields are spaces.
  71. */
  72. Oid confrelid; /* relation referenced by foreign key */
  73. char confupdtype; /* foreign key's ON UPDATE action */
  74. char confdeltype; /* foreign key's ON DELETE action */
  75. char confmatchtype; /* foreign key's match type */
  76. /* Has a local definition (hence, do not drop when coninhcount is 0) */
  77. bool conislocal;
  78. /* Number of times inherited from direct parent relation(s) */
  79. int32 coninhcount;
  80. /* Has a local definition and cannot be inherited */
  81. bool connoinherit;
  82. #ifdef CATALOG_VARLEN /* variable-length fields start here */
  83. /*
  84. * Columns of conrelid that the constraint applies to, if known (this is
  85. * NULL for trigger constraints)
  86. */
  87. int16 conkey[1];
  88. /*
  89. * If a foreign key, the referenced columns of confrelid
  90. */
  91. int16 confkey[1];
  92. /*
  93. * If a foreign key, the OIDs of the PK = FK equality operators for each
  94. * column of the constraint
  95. */
  96. Oid conpfeqop[1];
  97. /*
  98. * If a foreign key, the OIDs of the PK = PK equality operators for each
  99. * column of the constraint (i.e., equality for the referenced columns)
  100. */
  101. Oid conppeqop[1];
  102. /*
  103. * If a foreign key, the OIDs of the FK = FK equality operators for each
  104. * column of the constraint (i.e., equality for the referencing columns)
  105. */
  106. Oid conffeqop[1];
  107. /*
  108. * If an exclusion constraint, the OIDs of the exclusion operators for
  109. * each column of the constraint
  110. */
  111. Oid conexclop[1];
  112. /*
  113. * If a check constraint, nodeToString representation of expression
  114. */
  115. pg_node_tree conbin;
  116. /*
  117. * If a check constraint, source-text representation of expression
  118. */
  119. text consrc;
  120. #endif
  121. } FormData_pg_constraint;
  122. /* ----------------
  123. * Form_pg_constraint corresponds to a pointer to a tuple with
  124. * the format of pg_constraint relation.
  125. * ----------------
  126. */
  127. typedef FormData_pg_constraint *Form_pg_constraint;
  128. /* ----------------
  129. * compiler constants for pg_constraint
  130. * ----------------
  131. */
  132. #define Natts_pg_constraint 24
  133. #define Anum_pg_constraint_conname 1
  134. #define Anum_pg_constraint_connamespace 2
  135. #define Anum_pg_constraint_contype 3
  136. #define Anum_pg_constraint_condeferrable 4
  137. #define Anum_pg_constraint_condeferred 5
  138. #define Anum_pg_constraint_convalidated 6
  139. #define Anum_pg_constraint_conrelid 7
  140. #define Anum_pg_constraint_contypid 8
  141. #define Anum_pg_constraint_conindid 9
  142. #define Anum_pg_constraint_confrelid 10
  143. #define Anum_pg_constraint_confupdtype 11
  144. #define Anum_pg_constraint_confdeltype 12
  145. #define Anum_pg_constraint_confmatchtype 13
  146. #define Anum_pg_constraint_conislocal 14
  147. #define Anum_pg_constraint_coninhcount 15
  148. #define Anum_pg_constraint_connoinherit 16
  149. #define Anum_pg_constraint_conkey 17
  150. #define Anum_pg_constraint_confkey 18
  151. #define Anum_pg_constraint_conpfeqop 19
  152. #define Anum_pg_constraint_conppeqop 20
  153. #define Anum_pg_constraint_conffeqop 21
  154. #define Anum_pg_constraint_conexclop 22
  155. #define Anum_pg_constraint_conbin 23
  156. #define Anum_pg_constraint_consrc 24
  157. /* ----------------
  158. * initial contents of pg_constraint
  159. * ----------------
  160. */
  161. /* nothing, at present */
  162. /* Valid values for contype */
  163. #define CONSTRAINT_CHECK 'c'
  164. #define CONSTRAINT_FOREIGN 'f'
  165. #define CONSTRAINT_PRIMARY 'p'
  166. #define CONSTRAINT_UNIQUE 'u'
  167. #define CONSTRAINT_TRIGGER 't'
  168. #define CONSTRAINT_EXCLUSION 'x'
  169. /*
  170. * Valid values for confupdtype and confdeltype are the FKCONSTR_ACTION_xxx
  171. * constants defined in parsenodes.h. Valid values for confmatchtype are
  172. * the FKCONSTR_MATCH_xxx constants defined in parsenodes.h.
  173. */
  174. #endif /* PG_CONSTRAINT_H */