]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
CREATE STATISTICS: improve misleading error message
authorPeter Eisentraut <peter@eisentraut.org>
Mon, 15 Sep 2025 09:38:58 +0000 (11:38 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Mon, 15 Sep 2025 10:11:48 +0000 (12:11 +0200)
The previous change (commit f225473cbae) was still not on target,
because it talked about relation kinds, which are not what is being
checked here.  Provide a more accurate message.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CACJufxEZ48toGH0Em_6vdsT57Y3L8pLF=DZCQ_gCii6=C3MeXw@mail.gmail.com

src/backend/tcop/utility.c
src/test/regress/expected/stats_ext.out

index 0cf1a8d80896dedd46fd4df04ef7a8660088010f..2b1cb364896c4ff36436bec70313cc0a6279ada4 100644 (file)
@@ -1863,8 +1863,7 @@ ProcessUtilitySlow(ParseState *pstate,
                                        if (!IsA(rel, RangeVar))
                                                ereport(ERROR,
                                                                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                                                                errmsg("cannot create statistics on the specified relation"),
-                                                                errdetail("CREATE STATISTICS only supports tables, foreign tables and materialized views.")));
+                                                                errmsg("CREATE STATISTICS only supports relation names in the FROM clause")));
 
                                        /*
                                         * CREATE STATISTICS will influence future execution plans
index f3cc305381bfb3f55f5caf035b03c6a895c746b3..a1592c7c8ceb5e5e04401da8f054971b2f2cdc2c 100644 (file)
@@ -56,26 +56,20 @@ CREATE STATISTICS tst (unrecognized) ON x, y FROM ext_stats_test;
 ERROR:  unrecognized statistics kind "unrecognized"
 -- unsupported targets
 CREATE STATISTICS tst ON a FROM (VALUES (x)) AS foo;
-ERROR:  cannot create statistics on the specified relation
-DETAIL:  CREATE STATISTICS only supports tables, foreign tables and materialized views.
+ERROR:  CREATE STATISTICS only supports relation names in the FROM clause
 CREATE STATISTICS tst ON a FROM foo NATURAL JOIN bar;
-ERROR:  cannot create statistics on the specified relation
-DETAIL:  CREATE STATISTICS only supports tables, foreign tables and materialized views.
+ERROR:  CREATE STATISTICS only supports relation names in the FROM clause
 CREATE STATISTICS tst ON a FROM (SELECT * FROM ext_stats_test) AS foo;
-ERROR:  cannot create statistics on the specified relation
-DETAIL:  CREATE STATISTICS only supports tables, foreign tables and materialized views.
+ERROR:  CREATE STATISTICS only supports relation names in the FROM clause
 CREATE STATISTICS tst ON a FROM ext_stats_test s TABLESAMPLE system (x);
-ERROR:  cannot create statistics on the specified relation
-DETAIL:  CREATE STATISTICS only supports tables, foreign tables and materialized views.
+ERROR:  CREATE STATISTICS only supports relation names in the FROM clause
 CREATE STATISTICS tst ON a FROM XMLTABLE('foo' PASSING 'bar' COLUMNS a text);
-ERROR:  cannot create statistics on the specified relation
-DETAIL:  CREATE STATISTICS only supports tables, foreign tables and materialized views.
+ERROR:  CREATE STATISTICS only supports relation names in the FROM clause
 CREATE FUNCTION tftest(int) returns table(a int, b int) as $$
 SELECT $1, $1+i FROM generate_series(1,5) g(i);
 $$ LANGUAGE sql IMMUTABLE STRICT;
 CREATE STATISTICS alt_stat2 ON a FROM tftest(1);
-ERROR:  cannot create statistics on the specified relation
-DETAIL:  CREATE STATISTICS only supports tables, foreign tables and materialized views.
+ERROR:  CREATE STATISTICS only supports relation names in the FROM clause
 DROP FUNCTION tftest;
 -- incorrect expressions
 CREATE STATISTICS tst ON (y) FROM ext_stats_test; -- single column reference