Hi,

According to the syntax in ALTER INDEX doc, a column should be specified by
column number as discussed in [1]. However, the current code still allows to
use an internal column name like "expr". Is this intentional?

Although it is harmless, how about forbiding this undocumented and
unuseful behavior. The attached patch does it.

[1] 
https://www.postgresql.org/message-id/CAPpHfdsSYo6xpt0F%3DngAdqMPFJJhC7zApde9h1qwkdpHpwFisA%40mail.gmail.com

-- 
Yugo Nagata <nag...@sraoss.co.jp>
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 7c0cf0d..1b6f278 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -6430,6 +6430,12 @@ ATPrepSetStatistics(Relation rel, const char *colName, int16 colNum, Node *newVa
 		ereport(ERROR,
 				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
 				 errmsg("cannot refer to non-index column by number")));
+	else if ((rel->rd_rel->relkind == RELKIND_INDEX ||
+			  rel->rd_rel->relkind == RELKIND_PARTITIONED_INDEX) &&
+			  colName)
+		ereport(ERROR,
+				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+				 errmsg("cannot refer to expression index column by name")));
 
 	/* Permissions checks */
 	if (!pg_class_ownercheck(RelationGetRelid(rel), GetUserId()))

Reply via email to