Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcb05f53

Browse files
committed
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 canjust look at the actual names in the source index, instead. Do some minorformatting cleanup too.
1 parent7d672e1 commitcb05f53

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

‎src/backend/parser/parse_utilcmd.c

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
2020
* Portions Copyright (c) 1994, Regents of the University of California
2121
*
22-
*$PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.32 2009/12/15 17:57:47 tgl Exp $
22+
*$PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.33 2009/12/20 18:28:14 tgl Exp $
2323
*
2424
*-------------------------------------------------------------------------
2525
*/
@@ -745,58 +745,62 @@ transformInhRelation(ParseState *pstate, CreateStmtContext *cxt,
745745
/* Copy comment on index */
746746
if (inhRelation->options&CREATE_TABLE_LIKE_COMMENTS)
747747
{
748+
Form_pg_attribute*attrs;
748749
CommentStmt*stmt;
749-
ListCell*lc;
750-
inti;
750+
intcolno;
751751

752752
comment=GetComment(parent_index_oid,RelationRelationId,0);
753753

754754
if (comment!=NULL)
755755
{
756-
/* Assign name for index because CommentStmt requires name. */
756+
/*
757+
* We have to assign the index a name now, so that we
758+
* can reference it in CommentStmt.
759+
*/
757760
if (index_stmt->idxname==NULL)
758-
index_stmt->idxname=chooseIndexName(cxt->relation,index_stmt);
761+
index_stmt->idxname=chooseIndexName(cxt->relation,
762+
index_stmt);
759763

760764
stmt=makeNode(CommentStmt);
761765
stmt->objtype=OBJECT_INDEX;
762-
stmt->objname=list_make2(makeString(cxt->relation->schemaname),
763-
makeString(index_stmt->idxname));
766+
stmt->objname=
767+
list_make2(makeString(cxt->relation->schemaname),
768+
makeString(index_stmt->idxname));
764769
stmt->objargs=NIL;
765770
stmt->comment=comment;
766771

767772
cxt->alist=lappend(cxt->alist,stmt);
768773
}
769774

770-
/* Copy comment on index's columns */
771-
i=0;
772-
foreach(lc,index_stmt->indexParams)
775+
/* Copy comments on index's columns */
776+
attrs=RelationGetDescr(parent_index)->attrs;
777+
for (colno=1;
778+
colno <=RelationGetNumberOfAttributes(parent_index);
779+
colno++)
773780
{
774781
char*attname;
775782

776-
i++;
777-
comment=GetComment(parent_index_oid,RelationRelationId,i);
783+
comment=GetComment(parent_index_oid,RelationRelationId,
784+
colno);
778785
if (comment==NULL)
779786
continue;
780787

781-
/* Assign name for index because CommentStmt requires name. */
788+
/*
789+
* We have to assign the index a name now, so that we
790+
* can reference it in CommentStmt.
791+
*/
782792
if (index_stmt->idxname==NULL)
783-
index_stmt->idxname=chooseIndexName(cxt->relation,index_stmt);
793+
index_stmt->idxname=chooseIndexName(cxt->relation,
794+
index_stmt);
784795

785-
attname= ((IndexElem*)lfirst(lc))->name;
786-
787-
/* expression index has a dummy column name */
788-
if (attname==NULL)
789-
{
790-
attname=palloc(NAMEDATALEN);
791-
sprintf(attname,"pg_expression_%d",i);
792-
}
796+
attname=NameStr(attrs[colno-1]->attname);
793797

794798
stmt=makeNode(CommentStmt);
795799
stmt->objtype=OBJECT_COLUMN;
796-
stmt->objname=list_make3(
797-
makeString(cxt->relation->schemaname),
798-
makeString(index_stmt->idxname),
799-
makeString(attname));
800+
stmt->objname=
801+
list_make3(makeString(cxt->relation->schemaname),
802+
makeString(index_stmt->idxname),
803+
makeString(attname));
800804
stmt->objargs=NIL;
801805
stmt->comment=comment;
802806

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp