empty column name in error message

Started by Amit Langoteabout 6 years ago4 messages
#1Amit Langote
amitlangote09@gmail.com
1 attachment(s)

Hi,

I wonder if it's worthwhile to fix the following not-so-friendly error message:

create index on foo ((row(a)));
ERROR: column "" has pseudo-type record

For example, the attached patch makes it this:

create index on foo ((row(a)));
ERROR: column "row" has pseudo-type record

Note that "row" as column name has been automatically chosen by the caller.

Thanks,
Amit

Attachments:

ConstructTupleDescriptor-set-attname-earlier.patchapplication/octet-stream; name=ConstructTupleDescriptor-set-attname-earlier.patchDownload
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index e9955707fa..79439a0c66 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -312,6 +312,14 @@ ConstructTupleDescriptor(Relation heapRelation,
 		to->attcollation = (i < numkeyatts) ?
 			collationObjectId[i] : InvalidOid;
 
+		/*
+		 * Set the attribute name as specified by caller.
+		 */
+		if (colnames_item == NULL)	/* shouldn't happen */
+			elog(ERROR, "too few entries in colnames list");
+		namestrcpy(&to->attname, (const char *) lfirst(colnames_item));
+		colnames_item = lnext(indexColNames, colnames_item);
+
 		/*
 		 * For simple index columns, we copy some pg_attribute fields from the
 		 * parent relation.  For expressions we have to look at the expression
@@ -329,7 +337,6 @@ ConstructTupleDescriptor(Relation heapRelation,
 			from = TupleDescAttr(heapTupDesc,
 								 AttrNumberGetAttrOffset(atnum));
 
-			namecpy(&to->attname, &from->attname);
 			to->atttypid = from->atttypid;
 			to->attlen = from->attlen;
 			to->attndims = from->attndims;
@@ -390,14 +397,6 @@ ConstructTupleDescriptor(Relation heapRelation,
 		 */
 		to->attrelid = InvalidOid;
 
-		/*
-		 * Set the attribute name as specified by caller.
-		 */
-		if (colnames_item == NULL)	/* shouldn't happen */
-			elog(ERROR, "too few entries in colnames list");
-		namestrcpy(&to->attname, (const char *) lfirst(colnames_item));
-		colnames_item = lnext(indexColNames, colnames_item);
-
 		/*
 		 * Check the opclass and index AM to see if either provides a keytype
 		 * (overriding the attribute type).  Opclass (if exists) takes
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Amit Langote (#1)
Re: empty column name in error message

Amit Langote <amitlangote09@gmail.com> writes:

I wonder if it's worthwhile to fix the following not-so-friendly error message:

create index on foo ((row(a)));
ERROR: column "" has pseudo-type record

Ugh. That used to work more nicely:

regression=# create index fooi on foo ((row(a)));
ERROR: column "pg_expression_1" has pseudo-type record

But that was back in 8.4 :-( ... 9.0 and up behave as you show.
I'm guessing we broke it when we rearranged the rules for naming
index expression columns.

For example, the attached patch makes it this:

create index on foo ((row(a)));
ERROR: column "row" has pseudo-type record

Haven't read the patch in any detail yet, but that seems like
an improvement. And I guess we need a test case, or we'll
break it again :-(

regards, tom lane

#3Amit Langote
amitlangote09@gmail.com
In reply to: Tom Lane (#2)
Re: empty column name in error message

On Wed, Dec 18, 2019 at 1:21 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Haven't read the patch in any detail yet, but that seems like
an improvement. And I guess we need a test case, or we'll
break it again :-(

Thanks for adding the test case.

Regards,
Amit

#4Michael Paquier
michael@paquier.xyz
In reply to: Amit Langote (#3)
Re: empty column name in error message

On Wed, Dec 18, 2019 at 11:23:17AM +0900, Amit Langote wrote:

Thanks for adding the test case.

For the archives: this has been applied as of 2acab05.
--
Michael