Commit cb05f538 authored by Tom Lane's avatar Tom Lane

There is no good reason for the CREATE TABLE LIKE INCLUDING COMMENTS code to

have hard-wired knowledge of the rules for naming index columns.  It can
just look at the actual names in the source index, instead.  Do some minor
formatting cleanup too.
parent 7d672e1e
......@@ -19,7 +19,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.32 2009/12/15 17:57:47 tgl Exp $
* $PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.33 2009/12/20 18:28:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -745,58 +745,62 @@ transformInhRelation(ParseState *pstate, CreateStmtContext *cxt,
/* Copy comment on index */
if (inhRelation->options & CREATE_TABLE_LIKE_COMMENTS)
{
Form_pg_attribute *attrs;
CommentStmt *stmt;
ListCell *lc;
int i;
int colno;
comment = GetComment(parent_index_oid, RelationRelationId, 0);
if (comment != NULL)
{
/* Assign name for index because CommentStmt requires name. */
/*
* We have to assign the index a name now, so that we
* can reference it in CommentStmt.
*/
if (index_stmt->idxname == NULL)
index_stmt->idxname = chooseIndexName(cxt->relation, index_stmt);
index_stmt->idxname = chooseIndexName(cxt->relation,
index_stmt);
stmt = makeNode(CommentStmt);
stmt->objtype = OBJECT_INDEX;
stmt->objname = list_make2(makeString(cxt->relation->schemaname),
makeString(index_stmt->idxname));
stmt->objname =
list_make2(makeString(cxt->relation->schemaname),
makeString(index_stmt->idxname));
stmt->objargs = NIL;
stmt->comment = comment;
cxt->alist = lappend(cxt->alist, stmt);
}
/* Copy comment on index's columns */
i = 0;
foreach(lc, index_stmt->indexParams)
/* Copy comments on index's columns */
attrs = RelationGetDescr(parent_index)->attrs;
for (colno = 1;
colno <= RelationGetNumberOfAttributes(parent_index);
colno++)
{
char *attname;
i++;
comment = GetComment(parent_index_oid, RelationRelationId, i);
comment = GetComment(parent_index_oid, RelationRelationId,
colno);
if (comment == NULL)
continue;
/* Assign name for index because CommentStmt requires name. */
/*
* We have to assign the index a name now, so that we
* can reference it in CommentStmt.
*/
if (index_stmt->idxname == NULL)
index_stmt->idxname = chooseIndexName(cxt->relation, index_stmt);
index_stmt->idxname = chooseIndexName(cxt->relation,
index_stmt);
attname = ((IndexElem *) lfirst(lc))->name;
/* expression index has a dummy column name */
if (attname == NULL)
{
attname = palloc(NAMEDATALEN);
sprintf(attname, "pg_expression_%d", i);
}
attname = NameStr(attrs[colno - 1]->attname);
stmt = makeNode(CommentStmt);
stmt->objtype = OBJECT_COLUMN;
stmt->objname = list_make3(
makeString(cxt->relation->schemaname),
makeString(index_stmt->idxname),
makeString(attname));
stmt->objname =
list_make3(makeString(cxt->relation->schemaname),
makeString(index_stmt->idxname),
makeString(attname));
stmt->objargs = NIL;
stmt->comment = comment;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment