PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
comment.h File Reference
Include dependency graph for comment.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

ObjectAddress CommentObject (CommentStmt *stmt)
 
void DeleteComments (Oid oid, Oid classoid, int32 subid)
 
void CreateComments (Oid oid, Oid classoid, int32 subid, char *comment)
 
void DeleteSharedComments (Oid oid, Oid classoid)
 
void CreateSharedComments (Oid oid, Oid classoid, char *comment)
 
char * GetComment (Oid oid, Oid classoid, int32 subid)
 

Function Documentation

ObjectAddress CommentObject ( CommentStmt stmt)

Definition at line 40 of file comment.c.

References check_object_ownership(), ObjectAddress::classId, CommentStmt::comment, CreateComments(), CreateSharedComments(), ereport, errcode(), errmsg(), ERROR, get_database_oid(), get_object_address(), GetUserId(), InvalidObjectAddress, linitial, list_length(), NoLock, NULL, CommentStmt::objargs, OBJECT_COLUMN, OBJECT_DATABASE, OBJECT_ROLE, OBJECT_TABLESPACE, ObjectAddress::objectId, ObjectAddress::objectSubId, CommentStmt::objname, CommentStmt::objtype, OidIsValid, RelationData::rd_rel, relation_close(), RelationGetRelationName, RELKIND_COMPOSITE_TYPE, RELKIND_FOREIGN_TABLE, RELKIND_MATVIEW, RELKIND_RELATION, RELKIND_VIEW, ShareUpdateExclusiveLock, strVal, and WARNING.

Referenced by ATExecCmd(), ProcessUtilitySlow(), and standard_ProcessUtility().

41 {
42  Relation relation;
44 
45  /*
46  * When loading a dump, we may see a COMMENT ON DATABASE for the old name
47  * of the database. Erroring out would prevent pg_restore from completing
48  * (which is really pg_restore's fault, but for now we will work around
49  * the problem here). Consensus is that the best fix is to treat wrong
50  * database name as a WARNING not an ERROR; hence, the following special
51  * case. (If the length of stmt->objname is not 1, get_object_address
52  * will throw an error below; that's OK.)
53  */
54  if (stmt->objtype == OBJECT_DATABASE && list_length(stmt->objname) == 1)
55  {
56  char *database = strVal(linitial(stmt->objname));
57 
58  if (!OidIsValid(get_database_oid(database, true)))
59  {
61  (errcode(ERRCODE_UNDEFINED_DATABASE),
62  errmsg("database \"%s\" does not exist", database)));
63  return address;
64  }
65  }
66 
67  /*
68  * Translate the parser representation that identifies this object into an
69  * ObjectAddress. get_object_address() will throw an error if the object
70  * does not exist, and will also acquire a lock on the target to guard
71  * against concurrent DROP operations.
72  */
73  address = get_object_address(stmt->objtype, stmt->objname, stmt->objargs,
74  &relation, ShareUpdateExclusiveLock, false);
75 
76  /* Require ownership of the target object. */
77  check_object_ownership(GetUserId(), stmt->objtype, address,
78  stmt->objname, stmt->objargs, relation);
79 
80  /* Perform other integrity checks as needed. */
81  switch (stmt->objtype)
82  {
83  case OBJECT_COLUMN:
84 
85  /*
86  * Allow comments only on columns of tables, views, materialized
87  * views, composite types, and foreign tables (which are the only
88  * relkinds for which pg_dump will dump per-column comments). In
89  * particular we wish to disallow comments on index columns,
90  * because the naming of an index's columns may change across PG
91  * versions, so dumping per-column comments could create reload
92  * failures.
93  */
94  if (relation->rd_rel->relkind != RELKIND_RELATION &&
95  relation->rd_rel->relkind != RELKIND_VIEW &&
96  relation->rd_rel->relkind != RELKIND_MATVIEW &&
97  relation->rd_rel->relkind != RELKIND_COMPOSITE_TYPE &&
98  relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE)
99  ereport(ERROR,
100  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
101  errmsg("\"%s\" is not a table, view, materialized view, composite type, or foreign table",
102  RelationGetRelationName(relation))));
103  break;
104  default:
105  break;
106  }
107 
108  /*
109  * Databases, tablespaces, and roles are cluster-wide objects, so any
110  * comments on those objects are recorded in the shared pg_shdescription
111  * catalog. Comments on all other objects are recorded in pg_description.
112  */
113  if (stmt->objtype == OBJECT_DATABASE || stmt->objtype == OBJECT_TABLESPACE
114  || stmt->objtype == OBJECT_ROLE)
115  CreateSharedComments(address.objectId, address.classId, stmt->comment);
116  else
117  CreateComments(address.objectId, address.classId, address.objectSubId,
118  stmt->comment);
119 
120  /*
121  * If get_object_address() opened the relation for us, we close it to keep
122  * the reference count correct - but we retain any locks acquired by
123  * get_object_address() until commit time, to guard against concurrent
124  * activity.
125  */
126  if (relation != NULL)
127  relation_close(relation, NoLock);
128 
129  return address;
130 }
ObjectType objtype
Definition: parsenodes.h:2491
List * objname
Definition: parsenodes.h:2492
Oid GetUserId(void)
Definition: miscinit.c:282
#define RELKIND_MATVIEW
Definition: pg_class.h:167
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: heapam.c:1263
void CreateComments(Oid oid, Oid classoid, int32 subid, char *comment)
Definition: comment.c:142
char * comment
Definition: parsenodes.h:2494
void CreateSharedComments(Oid oid, Oid classoid, char *comment)
Definition: comment.c:237
void check_object_ownership(Oid roleid, ObjectType objtype, ObjectAddress address, List *objname, List *objargs, Relation relation)
Form_pg_class rd_rel
Definition: rel.h:113
#define OidIsValid(objectId)
Definition: c.h:534
#define RELKIND_COMPOSITE_TYPE
Definition: pg_class.h:165
#define linitial(l)
Definition: pg_list.h:110
#define ERROR
Definition: elog.h:43
List * objargs
Definition: parsenodes.h:2493
#define NoLock
Definition: lockdefs.h:34
ObjectAddress get_object_address(ObjectType objtype, List *objname, List *objargs, Relation *relp, LOCKMODE lockmode, bool missing_ok)
#define RelationGetRelationName(relation)
Definition: rel.h:433
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:166
#define ereport(elevel, rest)
Definition: elog.h:122
#define WARNING
Definition: elog.h:40
Oid get_database_oid(const char *dbname, bool missing_ok)
Definition: dbcommands.c:2001
#define ShareUpdateExclusiveLock
Definition: lockdefs.h:39
#define NULL
Definition: c.h:226
static int list_length(const List *l)
Definition: pg_list.h:89
const ObjectAddress InvalidObjectAddress
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define RELKIND_VIEW
Definition: pg_class.h:164
#define RELKIND_RELATION
Definition: pg_class.h:160
void CreateComments ( Oid  oid,
Oid  classoid,
int32  subid,
char *  comment 
)

Definition at line 142 of file comment.c.

References Anum_pg_description_classoid, Anum_pg_description_description, Anum_pg_description_objoid, Anum_pg_description_objsubid, BTEqualStrategyNumber, CatalogTupleDelete(), CatalogTupleInsert(), CatalogTupleUpdate(), CStringGetTextDatum, DescriptionObjIndexId, DescriptionRelationId, heap_close, heap_form_tuple(), heap_freetuple(), heap_modify_tuple(), heap_open(), i, Int32GetDatum, Natts_pg_description, NoLock, NULL, ObjectIdGetDatum, RelationGetDescr, RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, and values.

Referenced by CommentObject(), CreateExtensionInternal(), and DefineIndex().

143 {
144  Relation description;
145  ScanKeyData skey[3];
146  SysScanDesc sd;
147  HeapTuple oldtuple;
148  HeapTuple newtuple = NULL;
150  bool nulls[Natts_pg_description];
151  bool replaces[Natts_pg_description];
152  int i;
153 
154  /* Reduce empty-string to NULL case */
155  if (comment != NULL && strlen(comment) == 0)
156  comment = NULL;
157 
158  /* Prepare to form or update a tuple, if necessary */
159  if (comment != NULL)
160  {
161  for (i = 0; i < Natts_pg_description; i++)
162  {
163  nulls[i] = false;
164  replaces[i] = true;
165  }
166  values[Anum_pg_description_objoid - 1] = ObjectIdGetDatum(oid);
167  values[Anum_pg_description_classoid - 1] = ObjectIdGetDatum(classoid);
168  values[Anum_pg_description_objsubid - 1] = Int32GetDatum(subid);
170  }
171 
172  /* Use the index to search for a matching old tuple */
173 
174  ScanKeyInit(&skey[0],
176  BTEqualStrategyNumber, F_OIDEQ,
177  ObjectIdGetDatum(oid));
178  ScanKeyInit(&skey[1],
180  BTEqualStrategyNumber, F_OIDEQ,
181  ObjectIdGetDatum(classoid));
182  ScanKeyInit(&skey[2],
184  BTEqualStrategyNumber, F_INT4EQ,
185  Int32GetDatum(subid));
186 
188 
189  sd = systable_beginscan(description, DescriptionObjIndexId, true,
190  NULL, 3, skey);
191 
192  while ((oldtuple = systable_getnext(sd)) != NULL)
193  {
194  /* Found the old tuple, so delete or update it */
195 
196  if (comment == NULL)
197  CatalogTupleDelete(description, &oldtuple->t_self);
198  else
199  {
200  newtuple = heap_modify_tuple(oldtuple, RelationGetDescr(description), values,
201  nulls, replaces);
202  CatalogTupleUpdate(description, &oldtuple->t_self, newtuple);
203  }
204 
205  break; /* Assume there can be only one match */
206  }
207 
208  systable_endscan(sd);
209 
210  /* If we didn't find an old tuple, insert a new one */
211 
212  if (newtuple == NULL && comment != NULL)
213  {
214  newtuple = heap_form_tuple(RelationGetDescr(description),
215  values, nulls);
216  CatalogTupleInsert(description, newtuple);
217  }
218 
219  if (newtuple != NULL)
220  heap_freetuple(newtuple);
221 
222  /* Done */
223 
224  heap_close(description, NoLock);
225 }
#define Anum_pg_description_classoid
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define RelationGetDescr(relation)
Definition: rel.h:425
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:255
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:692
#define heap_close(r, l)
Definition: heapam.h:97
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1374
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
#define Anum_pg_description_objoid
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
Oid CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:162
ItemPointerData t_self
Definition: htup.h:65
#define Natts_pg_description
#define NoLock
Definition: lockdefs.h:34
#define RowExclusiveLock
Definition: lockdefs.h:38
#define Anum_pg_description_description
uintptr_t Datum
Definition: postgres.h:374
#define Anum_pg_description_objsubid
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define NULL
Definition: c.h:226
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:210
#define DescriptionRelationId
static Datum values[MAXATTR]
Definition: bootstrap.c:162
#define Int32GetDatum(X)
Definition: postgres.h:487
int i
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define CStringGetTextDatum(s)
Definition: builtins.h:90
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
Definition: heaptuple.c:793
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define DescriptionObjIndexId
Definition: indexing.h:150
void CreateSharedComments ( Oid  oid,
Oid  classoid,
char *  comment 
)

Definition at line 237 of file comment.c.

References Anum_pg_shdescription_classoid, Anum_pg_shdescription_description, Anum_pg_shdescription_objoid, BTEqualStrategyNumber, CatalogTupleDelete(), CatalogTupleInsert(), CatalogTupleUpdate(), CStringGetTextDatum, heap_close, heap_form_tuple(), heap_freetuple(), heap_modify_tuple(), heap_open(), i, Natts_pg_shdescription, NoLock, NULL, ObjectIdGetDatum, RelationGetDescr, RowExclusiveLock, ScanKeyInit(), SharedDescriptionObjIndexId, SharedDescriptionRelationId, systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, and values.

Referenced by CommentObject().

238 {
239  Relation shdescription;
240  ScanKeyData skey[2];
241  SysScanDesc sd;
242  HeapTuple oldtuple;
243  HeapTuple newtuple = NULL;
245  bool nulls[Natts_pg_shdescription];
246  bool replaces[Natts_pg_shdescription];
247  int i;
248 
249  /* Reduce empty-string to NULL case */
250  if (comment != NULL && strlen(comment) == 0)
251  comment = NULL;
252 
253  /* Prepare to form or update a tuple, if necessary */
254  if (comment != NULL)
255  {
256  for (i = 0; i < Natts_pg_shdescription; i++)
257  {
258  nulls[i] = false;
259  replaces[i] = true;
260  }
262  values[Anum_pg_shdescription_classoid - 1] = ObjectIdGetDatum(classoid);
264  }
265 
266  /* Use the index to search for a matching old tuple */
267 
268  ScanKeyInit(&skey[0],
270  BTEqualStrategyNumber, F_OIDEQ,
271  ObjectIdGetDatum(oid));
272  ScanKeyInit(&skey[1],
274  BTEqualStrategyNumber, F_OIDEQ,
275  ObjectIdGetDatum(classoid));
276 
278 
279  sd = systable_beginscan(shdescription, SharedDescriptionObjIndexId, true,
280  NULL, 2, skey);
281 
282  while ((oldtuple = systable_getnext(sd)) != NULL)
283  {
284  /* Found the old tuple, so delete or update it */
285 
286  if (comment == NULL)
287  CatalogTupleDelete(shdescription, &oldtuple->t_self);
288  else
289  {
290  newtuple = heap_modify_tuple(oldtuple, RelationGetDescr(shdescription),
291  values, nulls, replaces);
292  CatalogTupleUpdate(shdescription, &oldtuple->t_self, newtuple);
293  }
294 
295  break; /* Assume there can be only one match */
296  }
297 
298  systable_endscan(sd);
299 
300  /* If we didn't find an old tuple, insert a new one */
301 
302  if (newtuple == NULL && comment != NULL)
303  {
304  newtuple = heap_form_tuple(RelationGetDescr(shdescription),
305  values, nulls);
306  CatalogTupleInsert(shdescription, newtuple);
307  }
308 
309  if (newtuple != NULL)
310  heap_freetuple(newtuple);
311 
312  /* Done */
313 
314  heap_close(shdescription, NoLock);
315 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define RelationGetDescr(relation)
Definition: rel.h:425
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:255
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:692
#define heap_close(r, l)
Definition: heapam.h:97
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1374
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
Oid CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:162
ItemPointerData t_self
Definition: htup.h:65
#define NoLock
Definition: lockdefs.h:34
#define RowExclusiveLock
Definition: lockdefs.h:38
#define SharedDescriptionRelationId
#define Anum_pg_shdescription_classoid
#define Natts_pg_shdescription
uintptr_t Datum
Definition: postgres.h:374
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define Anum_pg_shdescription_description
#define SharedDescriptionObjIndexId
Definition: indexing.h:152
#define NULL
Definition: c.h:226
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:210
#define Anum_pg_shdescription_objoid
static Datum values[MAXATTR]
Definition: bootstrap.c:162
int i
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define CStringGetTextDatum(s)
Definition: builtins.h:90
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
Definition: heaptuple.c:793
#define BTEqualStrategyNumber
Definition: stratnum.h:31
void DeleteComments ( Oid  oid,
Oid  classoid,
int32  subid 
)

Definition at line 325 of file comment.c.

References Anum_pg_description_classoid, Anum_pg_description_objoid, Anum_pg_description_objsubid, BTEqualStrategyNumber, CatalogTupleDelete(), DescriptionObjIndexId, DescriptionRelationId, heap_close, heap_open(), Int32GetDatum, NULL, ObjectIdGetDatum, RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), and HeapTupleData::t_self.

Referenced by deleteOneObject().

326 {
327  Relation description;
328  ScanKeyData skey[3];
329  int nkeys;
330  SysScanDesc sd;
331  HeapTuple oldtuple;
332 
333  /* Use the index to search for all matching old tuples */
334 
335  ScanKeyInit(&skey[0],
337  BTEqualStrategyNumber, F_OIDEQ,
338  ObjectIdGetDatum(oid));
339  ScanKeyInit(&skey[1],
341  BTEqualStrategyNumber, F_OIDEQ,
342  ObjectIdGetDatum(classoid));
343 
344  if (subid != 0)
345  {
346  ScanKeyInit(&skey[2],
348  BTEqualStrategyNumber, F_INT4EQ,
349  Int32GetDatum(subid));
350  nkeys = 3;
351  }
352  else
353  nkeys = 2;
354 
356 
357  sd = systable_beginscan(description, DescriptionObjIndexId, true,
358  NULL, nkeys, skey);
359 
360  while ((oldtuple = systable_getnext(sd)) != NULL)
361  CatalogTupleDelete(description, &oldtuple->t_self);
362 
363  /* Done */
364 
365  systable_endscan(sd);
366  heap_close(description, RowExclusiveLock);
367 }
#define Anum_pg_description_classoid
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:255
#define heap_close(r, l)
Definition: heapam.h:97
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
#define Anum_pg_description_objoid
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
ItemPointerData t_self
Definition: htup.h:65
#define RowExclusiveLock
Definition: lockdefs.h:38
#define Anum_pg_description_objsubid
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define NULL
Definition: c.h:226
#define DescriptionRelationId
#define Int32GetDatum(X)
Definition: postgres.h:487
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define DescriptionObjIndexId
Definition: indexing.h:150
void DeleteSharedComments ( Oid  oid,
Oid  classoid 
)

Definition at line 373 of file comment.c.

References Anum_pg_shdescription_classoid, Anum_pg_shdescription_objoid, BTEqualStrategyNumber, CatalogTupleDelete(), heap_close, heap_open(), NULL, ObjectIdGetDatum, RowExclusiveLock, ScanKeyInit(), SharedDescriptionObjIndexId, SharedDescriptionRelationId, systable_beginscan(), systable_endscan(), systable_getnext(), and HeapTupleData::t_self.

Referenced by dropdb(), DropRole(), and DropTableSpace().

374 {
375  Relation shdescription;
376  ScanKeyData skey[2];
377  SysScanDesc sd;
378  HeapTuple oldtuple;
379 
380  /* Use the index to search for all matching old tuples */
381 
382  ScanKeyInit(&skey[0],
384  BTEqualStrategyNumber, F_OIDEQ,
385  ObjectIdGetDatum(oid));
386  ScanKeyInit(&skey[1],
388  BTEqualStrategyNumber, F_OIDEQ,
389  ObjectIdGetDatum(classoid));
390 
392 
393  sd = systable_beginscan(shdescription, SharedDescriptionObjIndexId, true,
394  NULL, 2, skey);
395 
396  while ((oldtuple = systable_getnext(sd)) != NULL)
397  CatalogTupleDelete(shdescription, &oldtuple->t_self);
398 
399  /* Done */
400 
401  systable_endscan(sd);
402  heap_close(shdescription, RowExclusiveLock);
403 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:255
#define heap_close(r, l)
Definition: heapam.h:97
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
ItemPointerData t_self
Definition: htup.h:65
#define RowExclusiveLock
Definition: lockdefs.h:38
#define SharedDescriptionRelationId
#define Anum_pg_shdescription_classoid
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define SharedDescriptionObjIndexId
Definition: indexing.h:152
#define NULL
Definition: c.h:226
#define Anum_pg_shdescription_objoid
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31
char* GetComment ( Oid  oid,
Oid  classoid,
int32  subid 
)

Definition at line 409 of file comment.c.

References AccessShareLock, Anum_pg_description_classoid, Anum_pg_description_description, Anum_pg_description_objoid, Anum_pg_description_objsubid, BTEqualStrategyNumber, DescriptionObjIndexId, DescriptionRelationId, heap_close, heap_getattr, heap_open(), Int32GetDatum, NULL, ObjectIdGetDatum, RelationGetDescr, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), TextDatumGetCString, and value.

Referenced by ATPostAlterTypeParse(), RebuildConstraintComment(), and transformTableLikeClause().

410 {
411  Relation description;
412  ScanKeyData skey[3];
413  SysScanDesc sd;
414  TupleDesc tupdesc;
415  HeapTuple tuple;
416  char *comment;
417 
418  /* Use the index to search for a matching old tuple */
419 
420  ScanKeyInit(&skey[0],
422  BTEqualStrategyNumber, F_OIDEQ,
423  ObjectIdGetDatum(oid));
424  ScanKeyInit(&skey[1],
426  BTEqualStrategyNumber, F_OIDEQ,
427  ObjectIdGetDatum(classoid));
428  ScanKeyInit(&skey[2],
430  BTEqualStrategyNumber, F_INT4EQ,
431  Int32GetDatum(subid));
432 
434  tupdesc = RelationGetDescr(description);
435 
436  sd = systable_beginscan(description, DescriptionObjIndexId, true,
437  NULL, 3, skey);
438 
439  comment = NULL;
440  while ((tuple = systable_getnext(sd)) != NULL)
441  {
442  Datum value;
443  bool isnull;
444 
445  /* Found the tuple, get description field */
446  value = heap_getattr(tuple, Anum_pg_description_description, tupdesc, &isnull);
447  if (!isnull)
448  comment = TextDatumGetCString(value);
449  break; /* Assume there can be only one match */
450  }
451 
452  systable_endscan(sd);
453 
454  /* Done */
455  heap_close(description, AccessShareLock);
456 
457  return comment;
458 }
static struct @76 value
#define Anum_pg_description_classoid
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define RelationGetDescr(relation)
Definition: rel.h:425
#define AccessShareLock
Definition: lockdefs.h:36
#define heap_close(r, l)
Definition: heapam.h:97
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
#define Anum_pg_description_objoid
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define Anum_pg_description_description
#define heap_getattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:769
#define TextDatumGetCString(d)
Definition: builtins.h:91
uintptr_t Datum
Definition: postgres.h:374
#define Anum_pg_description_objsubid
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define NULL
Definition: c.h:226
#define DescriptionRelationId
#define Int32GetDatum(X)
Definition: postgres.h:487
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define DescriptionObjIndexId
Definition: indexing.h:150