misleading error message in ProcessUtilitySlow T_CreateStatsStmt

jian he <jian.universality@gmail.com>

From: jian he <jian.universality@gmail.com>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2025-08-21T11:59:14Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. CREATE STATISTICS: improve misleading error message

  2. Glossary: improve definition of "relation"

  3. Extended statistics on expressions

hi.

while reviewing other work, some error messages in src/backend/tcop/utility.c
seem not accurate.

static void
ProcessUtilitySlow(ParseState *pstate,
                   PlannedStmt *pstmt,
                   const char *queryString,
                   ProcessUtilityContext context,
                   ParamListInfo params,
                   QueryEnvironment *queryEnv,
                   DestReceiver *dest,
                   QueryCompletion *qc)

            case T_CreateStatsStmt:
                {
                    Oid            relid;
                    CreateStatsStmt *stmt = (CreateStatsStmt *) parsetree;
                    RangeVar   *rel = (RangeVar *) linitial(stmt->relations);

                    if (!IsA(rel, RangeVar))
                        ereport(ERROR,
                                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                                 errmsg("only a single relation is
allowed in CREATE STATISTICS")));
                    relid = RangeVarGetRelid(rel,
ShareUpdateExclusiveLock, false);
                    /* Run parse analysis ... */
                    stmt = transformStatsStmt(relid, stmt, queryString);
                    address = CreateStatistics(stmt);
                }


for example:

create or replace function tftest(int) returns table(a int, b int) as $$
begin
  return query select $1, $1+i from generate_series(1,5) g(i);
end;
$$ language plpgsql immutable strict;

CREATE STATISTICS alt_stat2 ON a, b FROM tftest(1);
ERROR:  only a single relation is allowed in CREATE STATISTICS

this error message seem misleading?
also this error check seems duplicated in CreateStatistics?