diff options
Diffstat (limited to 'src/backend/commands/creatinh.c')
-rw-r--r-- | src/backend/commands/creatinh.c | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/src/backend/commands/creatinh.c b/src/backend/commands/creatinh.c index 0b2d2360b3c..9463d55a6a1 100644 --- a/src/backend/commands/creatinh.c +++ b/src/backend/commands/creatinh.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.48 1999/10/03 23:55:27 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.49 1999/10/15 01:49:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -16,10 +16,12 @@ #include "access/heapam.h" #include "catalog/catname.h" +#include "catalog/indexing.h" #include "catalog/heap.h" #include "catalog/pg_inherits.h" #include "catalog/pg_ipl.h" #include "catalog/pg_type.h" +#include "catalog/pg_description.h" #include "commands/creatinh.h" #include "utils/syscache.h" @@ -232,6 +234,52 @@ TruncateRelation(char *name) heap_truncate(name); } +/*------------------------------------------------------------------ + * CommentRelation -- + * Adds a comment to pg_description for the associated + * relation or relation attribute. + * + * Note: + * The comment is dropped on the relation or attribute if + * the comment is an empty string. + *------------------------------------------------------------------ + */ +void +CommentRelation(char *relname, char *attrname, char *comments) +{ + + Relation relation; + HeapTuple attrtuple; + Oid oid; + + /*** First ensure relname is valid ***/ + + relation = heap_openr(relname, AccessShareLock); + + /*** Now, if an attribute was specified, fetch its oid, else use relation's oid ***/ + + if (attrname != NULL) { + attrtuple = SearchSysCacheTuple(ATTNAME, ObjectIdGetDatum(relation->rd_id), + PointerGetDatum(attrname), 0, 0); + if (!HeapTupleIsValid(attrtuple)) { + elog(ERROR, "CommentRelation: attribute \"%s\" is not an attribute of relation \"%s\"", + attrname, relname); + } + oid = attrtuple->t_data->t_oid; + } else { + oid = RelationGetRelid(relation); + } + + /*** Call CreateComments() to create/drop the comments ***/ + + CreateComments(oid, comments); + + /*** Now, close the heap relation ***/ + + heap_close(relation, AccessShareLock); + +} + /* * MergeAttributes * Returns new schema given initial schema and supers. |