aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2019-12-17 17:44:27 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2019-12-17 17:44:27 -0500
commit2acab054b3ff8e46707727980ce3fa1a1897381f (patch)
tree76d124a60e61bd1fadd88978422206ecf40396fa /src/backend
parent5184f110aa4130ec87b0b3e0834292cd8cb1fd8a (diff)
downloadpostgresql-2acab054b3ff8e46707727980ce3fa1a1897381f.tar.gz
postgresql-2acab054b3ff8e46707727980ce3fa1a1897381f.zip
Fix error reporting for index expressions of prohibited types.
If CheckAttributeType() threw an error about the datatype of an index expression column, it would report an empty column name, which is pretty unhelpful and certainly not the intended behavior. I (tgl) evidently broke this in commit cfc5008a5, by not noticing that the column's attname was used above where I'd placed the assignment of it. In HEAD and v12, this is trivially fixable by moving up the assignment of attname. Before v12 the code is a bit more messy; to avoid doing substantial refactoring, I took the lazy way out and just put in two copies of the assignment code. Report and patch by Amit Langote. Back-patch to all supported branches. Discussion: https://postgr.es/m/CA+HiwqFA+BGyBFimjiYXXMa2Hc3fcL0+OJOyzUNjhU4NCa_XXw@mail.gmail.com
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/catalog/index.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index e9955707fa7..79439a0c66d 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -313,6 +313,14 @@ ConstructTupleDescriptor(Relation heapRelation,
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
* result.
@@ -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;
@@ -391,14 +398,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
* precedence.