From 653aa603f501aa6e4865105a928cd13082ee7152 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 11 Dec 2020 17:54:10 -0500 Subject: Provide an error cursor for "can't subscript" error messages. Commit c7aba7c14 didn't add this, but after more fooling with the feature I feel that it'd be useful. To make this possible, refactor getSubscriptingRoutines() so that the caller is responsible for throwing any error. (In clauses.c, I just chose to make the most conservative assumption rather than throwing an error. We don't expect failures there anyway really, so the code space for an error message would be a poor investment.) --- src/backend/executor/execExpr.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/backend/executor') diff --git a/src/backend/executor/execExpr.c b/src/backend/executor/execExpr.c index 0134ecc261e..5c3210a9cca 100644 --- a/src/backend/executor/execExpr.c +++ b/src/backend/executor/execExpr.c @@ -2536,6 +2536,14 @@ ExecInitSubscriptingRef(ExprEvalStep *scratch, SubscriptingRef *sbsref, /* Look up the subscripting support methods */ sbsroutines = getSubscriptingRoutines(sbsref->refcontainertype, NULL); + if (!sbsroutines) + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("cannot subscript type %s because it does not support subscripting", + format_type_be(sbsref->refcontainertype)), + state->parent ? + executor_errposition(state->parent->state, + exprLocation((Node *) sbsref)) : 0)); /* Allocate sbsrefstate, with enough space for per-subscript arrays too */ sbsrefstate = palloc0(MAXALIGN(sizeof(SubscriptingRefState)) + -- cgit v1.2.3